Skip to content

Commit

Permalink
remove need for PandasError sub-class
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed Apr 3, 2017
1 parent 92b2fdc commit 7e8432d
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 21 deletions.
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,8 @@ Other API Changes
- ``NaT`` will now correctly return ``np.nan`` for ``Timedelta`` and ``Period`` accessors such as ``days`` and ``quarter`` (:issue:`15782`)
- ``NaT`` will now returns ``NaT`` for ``tz_localize`` and ``tz_convert``
methods (:issue:`15830`)
- ``DataFrame`` and ``Panel`` constructors with invalid input will now raise ``ValueError`` rather than ``PandasError``, if called with scalar inputs and not axes (:issue:`15541`)


.. _whatsnew_0200.deprecations:

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# compat
from pandas.errors import ( # noqa
PandasError, PerformanceWarning,
PerformanceWarning,
AmbiguousIndexError, UnsupportedFunctionCall, UnsortedIndexError)

# back-compat of public API
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
is_named_tuple)
from pandas.types.missing import isnull, notnull

from pandas.errors import PandasError
from pandas.core.common import (_try_sort,
_default_index,
_values_from_object,
Expand Down Expand Up @@ -348,7 +347,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
mgr = self._init_ndarray(values, index, columns, dtype=dtype,
copy=False)
else:
raise PandasError('DataFrame constructor not properly called!')
raise ValueError('DataFrame constructor not properly called!')

NDFrame.__init__(self, mgr, fastpath=True)

Expand Down
7 changes: 3 additions & 4 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from pandas import compat
from pandas.compat import (map, zip, range, u, OrderedDict, OrderedDefaultdict)
from pandas.compat.numpy import function as nv
from pandas.errors import PandasError
from pandas.core.common import _try_sort, _default_index
from pandas.core.frame import DataFrame
from pandas.core.generic import NDFrame, _shared_docs
Expand Down Expand Up @@ -175,7 +174,7 @@ def _init_data(self, data, copy, dtype, **kwargs):
copy=False)
copy = False
else: # pragma: no cover
raise PandasError('Panel constructor not properly called!')
raise ValueError('Panel constructor not properly called!')

NDFrame.__init__(self, mgr, axes=axes, copy=copy, dtype=dtype)

Expand Down Expand Up @@ -1151,8 +1150,8 @@ def _construct_return_type(self, result, axes=None):
return self._constructor_sliced(
result, **self._extract_axes_for_slice(self, axes))

raise PandasError('invalid _construct_return_type [self->%s] '
'[result->%s]' % (self, result))
raise ValueError('invalid _construct_return_type [self->%s] '
'[result->%s]' % (self, result))

def _wrap_result(self, result, axis):
axis = self._get_axis_name(axis)
Expand Down
6 changes: 1 addition & 5 deletions pandas/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
from pandas._libs.tslib import OutOfBoundsDatetime


class PandasError(Exception):
pass


class PerformanceWarning(Warning):
pass

class AmbiguousIndexError(PandasError, KeyError):
class AmbiguousIndexError(KeyError):
pass


Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from pandas import (DataFrame, Index, Series, isnull,
MultiIndex, Timedelta, Timestamp,
date_range)
from pandas.errors import PandasError
import pandas as pd
import pandas._libs.lib as lib
import pandas.util.testing as tm
Expand Down Expand Up @@ -773,7 +772,7 @@ def test_constructor_more(self):

# corner, silly
# TODO: Fix this Exception to be better...
with tm.assertRaisesRegexp(PandasError, 'constructor not '
with tm.assertRaisesRegexp(ValueError, 'constructor not '
'properly called'):
DataFrame((1, 2, 3))

Expand Down Expand Up @@ -1241,8 +1240,8 @@ def test_constructor_single_value(self):
dtype=object),
index=[1, 2], columns=['a', 'c']))

self.assertRaises(PandasError, DataFrame, 'a', [1, 2])
self.assertRaises(PandasError, DataFrame, 'a', columns=['a', 'c'])
self.assertRaises(ValueError, DataFrame, 'a', [1, 2])
self.assertRaises(ValueError, DataFrame, 'a', columns=['a', 'c'])
with tm.assertRaisesRegexp(TypeError, 'incompatible data and dtype'):
DataFrame('a', [1, 2], ['a', 'c'], float)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@pytest.mark.parametrize(
"exc", ['PandasError', 'AmbiguousIndexError',
"exc", ['AmbiguousIndexError',
'UnsupportedFunctionCall', 'UnsortedIndexError',
'OutOfBoundsDatetime',
'ParserError', 'PerformanceWarning', 'DtypeWarning',
Expand Down
6 changes: 2 additions & 4 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,7 @@ def _has_same_tz(self, other):
def _cached_range(cls, start=None, end=None, periods=None, offset=None,
name=None):
if start is None and end is None:
# I somewhat believe this should never be raised externally and
# therefore should be a `PandasError` but whatever...
# I somewhat believe this should never be raised externally
raise TypeError('Must specify either start or end.')
if start is not None:
start = Timestamp(start)
Expand All @@ -630,8 +629,7 @@ def _cached_range(cls, start=None, end=None, periods=None, offset=None,
'Must either specify period or provide both start and end.')

if offset is None:
# This can't happen with external-facing code, therefore
# PandasError
# This can't happen with external-facing code
raise TypeError('Must provide offset.')

drc = _daterange_cache
Expand Down

0 comments on commit 7e8432d

Please sign in to comment.