Skip to content

Commit 22c20f9

Browse files
committed
remove need for PandasError sub-class
1 parent fd2abde commit 22c20f9

File tree

8 files changed

+14
-21
lines changed

8 files changed

+14
-21
lines changed

doc/source/whatsnew/v0.20.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ Other API Changes
792792
ignored (no longer needed to specify the new behaviour) and is deprecated.
793793
- ``NaT`` will now correctly report ``False`` for datetimelike boolean operations such as ``is_month_start`` (:issue:`15781`)
794794
- ``NaT`` will now correctly return ``np.nan`` for ``Timedelta`` and ``Period`` accessors such as ``days`` and ``quarter`` (:issue:`15782`)
795+
- ``DataFrame`` and ``Panel`` constructors with invalid input will now raise ``ValueError`` rather than ``PandasError``, if called with scalar inputs and not axes (:issue:`15541`)
796+
795797

796798
.. _whatsnew_0200.deprecations:
797799

pandas/core/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
# compat
2424
from pandas.errors import ( # noqa
25-
PandasError, PerformanceWarning,
25+
PerformanceWarning,
2626
AmbiguousIndexError, UnsupportedFunctionCall, UnsortedIndexError)
2727

2828
# back-compat of public API

pandas/core/frame.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
is_named_tuple)
5757
from pandas.types.missing import isnull, notnull
5858

59-
from pandas.errors import PandasError
6059
from pandas.core.common import (_try_sort,
6160
_default_index,
6261
_values_from_object,
@@ -343,7 +342,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
343342
mgr = self._init_ndarray(values, index, columns, dtype=dtype,
344343
copy=False)
345344
else:
346-
raise PandasError('DataFrame constructor not properly called!')
345+
raise ValueError('DataFrame constructor not properly called!')
347346

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

pandas/core/panel.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from pandas import compat
2222
from pandas.compat import (map, zip, range, u, OrderedDict, OrderedDefaultdict)
2323
from pandas.compat.numpy import function as nv
24-
from pandas.errors import PandasError
2524
from pandas.core.common import _try_sort, _default_index
2625
from pandas.core.frame import DataFrame
2726
from pandas.core.generic import NDFrame, _shared_docs
@@ -175,7 +174,7 @@ def _init_data(self, data, copy, dtype, **kwargs):
175174
copy=False)
176175
copy = False
177176
else: # pragma: no cover
178-
raise PandasError('Panel constructor not properly called!')
177+
raise ValueError('Panel constructor not properly called!')
179178

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

@@ -1151,8 +1150,8 @@ def _construct_return_type(self, result, axes=None):
11511150
return self._constructor_sliced(
11521151
result, **self._extract_axes_for_slice(self, axes))
11531152

1154-
raise PandasError('invalid _construct_return_type [self->%s] '
1155-
'[result->%s]' % (self, result))
1153+
raise ValueError('invalid _construct_return_type [self->%s] '
1154+
'[result->%s]' % (self, result))
11561155

11571156
def _wrap_result(self, result, axis):
11581157
axis = self._get_axis_name(axis)

pandas/errors/__init__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
from pandas._libs.tslib import OutOfBoundsDatetime
66

77

8-
class PandasError(Exception):
9-
pass
10-
11-
128
class PerformanceWarning(Warning):
139
pass
1410

15-
class AmbiguousIndexError(PandasError, KeyError):
11+
class AmbiguousIndexError(KeyError):
1612
pass
1713

1814

pandas/tests/frame/test_constructors.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from pandas import (DataFrame, Index, Series, isnull,
2121
MultiIndex, Timedelta, Timestamp,
2222
date_range)
23-
from pandas.errors import PandasError
2423
import pandas as pd
2524
import pandas._libs.lib as lib
2625
import pandas.util.testing as tm
@@ -773,7 +772,7 @@ def test_constructor_more(self):
773772

774773
# corner, silly
775774
# TODO: Fix this Exception to be better...
776-
with tm.assertRaisesRegexp(PandasError, 'constructor not '
775+
with tm.assertRaisesRegexp(ValueError, 'constructor not '
777776
'properly called'):
778777
DataFrame((1, 2, 3))
779778

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

1244-
self.assertRaises(PandasError, DataFrame, 'a', [1, 2])
1245-
self.assertRaises(PandasError, DataFrame, 'a', columns=['a', 'c'])
1243+
self.assertRaises(ValueError, DataFrame, 'a', [1, 2])
1244+
self.assertRaises(ValueError, DataFrame, 'a', columns=['a', 'c'])
12461245
with tm.assertRaisesRegexp(TypeError, 'incompatible data and dtype'):
12471246
DataFrame('a', [1, 2], ['a', 'c'], float)
12481247

pandas/tests/test_errors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@pytest.mark.parametrize(
9-
"exc", ['PandasError', 'AmbiguousIndexError',
9+
"exc", ['AmbiguousIndexError',
1010
'UnsupportedFunctionCall', 'UnsortedIndexError',
1111
'OutOfBoundsDatetime',
1212
'ParserError', 'PerformanceWarning', 'DtypeWarning',

pandas/tseries/index.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,7 @@ def _has_same_tz(self, other):
618618
def _cached_range(cls, start=None, end=None, periods=None, offset=None,
619619
name=None):
620620
if start is None and end is None:
621-
# I somewhat believe this should never be raised externally and
622-
# therefore should be a `PandasError` but whatever...
621+
# I somewhat believe this should never be raised externally
623622
raise TypeError('Must specify either start or end.')
624623
if start is not None:
625624
start = Timestamp(start)
@@ -630,8 +629,7 @@ def _cached_range(cls, start=None, end=None, periods=None, offset=None,
630629
'Must either specify period or provide both start and end.')
631630

632631
if offset is None:
633-
# This can't happen with external-facing code, therefore
634-
# PandasError
632+
# This can't happen with external-facing code
635633
raise TypeError('Must provide offset.')
636634

637635
drc = _daterange_cache

0 commit comments

Comments
 (0)