Skip to content

Commit abec810

Browse files
dataxerikyehoshuadimarsky
authored andcommitted
ENH: move DataError from core/base.py to error/__init__.py per GH27656 (pandas-dev#47047)
1 parent e7140f3 commit abec810

File tree

10 files changed

+25
-17
lines changed

10 files changed

+25
-17
lines changed

doc/source/reference/testing.rst

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Exceptions and warnings
2626

2727
errors.AbstractMethodError
2828
errors.AccessorRegistrationWarning
29+
errors.DataError
2930
errors.DtypeWarning
3031
errors.DuplicateLabelError
3132
errors.EmptyDataError

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Other enhancements
151151
- A :class:`errors.PerformanceWarning` is now thrown when using ``string[pyarrow]`` dtype with methods that don't dispatch to ``pyarrow.compute`` methods (:issue:`42613`)
152152
- Added ``numeric_only`` argument to :meth:`Resampler.sum`, :meth:`Resampler.prod`, :meth:`Resampler.min`, :meth:`Resampler.max`, :meth:`Resampler.first`, and :meth:`Resampler.last` (:issue:`46442`)
153153
- ``times`` argument in :class:`.ExponentialMovingWindow` now accepts ``np.timedelta64`` (:issue:`47003`)
154+
- :class:`DataError` now exposed in ``pandas.errors`` (:issue:`27656`)
154155

155156
.. ---------------------------------------------------------------------------
156157
.. _whatsnew_150.notable_bug_fixes:

pandas/core/apply.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
Axis,
3434
NDFrameT,
3535
)
36+
from pandas.errors import DataError
3637
from pandas.util._decorators import cache_readonly
3738
from pandas.util._exceptions import find_stack_level
3839

@@ -51,7 +52,6 @@
5152

5253
from pandas.core.algorithms import safe_sort
5354
from pandas.core.base import (
54-
DataError,
5555
SelectionMixin,
5656
SpecificationError,
5757
)

pandas/core/base.py

-4
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ def __setattr__(self, key: str, value):
176176
object.__setattr__(self, key, value)
177177

178178

179-
class DataError(Exception):
180-
pass
181-
182-
183179
class SpecificationError(Exception):
184180
pass
185181

pandas/core/groupby/groupby.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ class providing the base-class of operations.
5353
npt,
5454
)
5555
from pandas.compat.numpy import function as nv
56-
from pandas.errors import AbstractMethodError
56+
from pandas.errors import (
57+
AbstractMethodError,
58+
DataError,
59+
)
5760
from pandas.util._decorators import (
5861
Appender,
5962
Substitution,
@@ -89,7 +92,6 @@ class providing the base-class of operations.
8992
ExtensionArray,
9093
)
9194
from pandas.core.base import (
92-
DataError,
9395
PandasObject,
9496
SelectionMixin,
9597
)

pandas/core/resample.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
npt,
3535
)
3636
from pandas.compat.numpy import function as nv
37-
from pandas.errors import AbstractMethodError
37+
from pandas.errors import (
38+
AbstractMethodError,
39+
DataError,
40+
)
3841
from pandas.util._decorators import (
3942
Appender,
4043
Substitution,
@@ -50,10 +53,7 @@
5053

5154
import pandas.core.algorithms as algos
5255
from pandas.core.apply import ResamplerWindowApply
53-
from pandas.core.base import (
54-
DataError,
55-
PandasObject,
56-
)
56+
from pandas.core.base import PandasObject
5757
import pandas.core.common as com
5858
from pandas.core.generic import (
5959
NDFrame,

pandas/core/window/rolling.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
)
3434
from pandas.compat._optional import import_optional_dependency
3535
from pandas.compat.numpy import function as nv
36+
from pandas.errors import DataError
3637
from pandas.util._decorators import doc
3738
from pandas.util._exceptions import find_stack_level
3839

@@ -54,10 +55,7 @@
5455
from pandas.core.algorithms import factorize
5556
from pandas.core.apply import ResamplerWindowApply
5657
from pandas.core.arrays import ExtensionArray
57-
from pandas.core.base import (
58-
DataError,
59-
SelectionMixin,
60-
)
58+
from pandas.core.base import SelectionMixin
6159
import pandas.core.common as com
6260
from pandas.core.indexers.objects import (
6361
BaseIndexer,

pandas/errors/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,11 @@ class InvalidIndexError(Exception):
236236
237237
.. versionadded:: 1.1.0
238238
"""
239+
240+
241+
class DataError(Exception):
242+
"""
243+
Exception raised when trying to perform a ohlc on a non-numnerical column.
244+
Or, it can be raised when trying to apply a function to a non-numerical
245+
column on a rolling window.
246+
"""

pandas/tests/test_errors.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"MergeError",
2020
"OptionError",
2121
"NumbaUtilError",
22+
"DataError",
2223
],
2324
)
2425
def test_exception_importable(exc):

pandas/tests/window/test_dtypes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import numpy as np
22
import pytest
33

4+
from pandas.errors import DataError
5+
46
from pandas.core.dtypes.common import pandas_dtype
57

68
from pandas import (
@@ -9,7 +11,6 @@
911
Series,
1012
)
1113
import pandas._testing as tm
12-
from pandas.core.base import DataError
1314

1415
# gh-12373 : rolling functions error on float32 data
1516
# make sure rolling functions works for different dtypes

0 commit comments

Comments
 (0)