Skip to content

ENH: move DataError from core/base.py to error/__init__.py per GH27656 #47047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/reference/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Exceptions and warnings

errors.AbstractMethodError
errors.AccessorRegistrationWarning
errors.DataError
errors.DtypeWarning
errors.DuplicateLabelError
errors.EmptyDataError
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Other enhancements
- A :class:`errors.PerformanceWarning` is now thrown when using ``string[pyarrow]`` dtype with methods that don't dispatch to ``pyarrow.compute`` methods (:issue:`42613`)
- 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`)
- ``times`` argument in :class:`.ExponentialMovingWindow` now accepts ``np.timedelta64`` (:issue:`47003`)
- :class:`DataError` now exposed in ``pandas.errors`` (:issue:`27656`)

.. ---------------------------------------------------------------------------
.. _whatsnew_150.notable_bug_fixes:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
Axis,
NDFrameT,
)
from pandas.errors import DataError
from pandas.util._decorators import cache_readonly
from pandas.util._exceptions import find_stack_level

Expand All @@ -51,7 +52,6 @@

from pandas.core.algorithms import safe_sort
from pandas.core.base import (
DataError,
SelectionMixin,
SpecificationError,
)
Expand Down
4 changes: 0 additions & 4 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ def __setattr__(self, key: str, value):
object.__setattr__(self, key, value)


class DataError(Exception):
pass


class SpecificationError(Exception):
pass

Expand Down
6 changes: 4 additions & 2 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class providing the base-class of operations.
npt,
)
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
from pandas.errors import (
AbstractMethodError,
DataError,
)
from pandas.util._decorators import (
Appender,
Substitution,
Expand Down Expand Up @@ -89,7 +92,6 @@ class providing the base-class of operations.
ExtensionArray,
)
from pandas.core.base import (
DataError,
PandasObject,
SelectionMixin,
)
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
npt,
)
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
from pandas.errors import (
AbstractMethodError,
DataError,
)
from pandas.util._decorators import (
Appender,
Substitution,
Expand All @@ -50,10 +53,7 @@

import pandas.core.algorithms as algos
from pandas.core.apply import ResamplerWindowApply
from pandas.core.base import (
DataError,
PandasObject,
)
from pandas.core.base import PandasObject
import pandas.core.common as com
from pandas.core.generic import (
NDFrame,
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)
from pandas.compat._optional import import_optional_dependency
from pandas.compat.numpy import function as nv
from pandas.errors import DataError
from pandas.util._decorators import doc
from pandas.util._exceptions import find_stack_level

Expand All @@ -54,10 +55,7 @@
from pandas.core.algorithms import factorize
from pandas.core.apply import ResamplerWindowApply
from pandas.core.arrays import ExtensionArray
from pandas.core.base import (
DataError,
SelectionMixin,
)
from pandas.core.base import SelectionMixin
import pandas.core.common as com
from pandas.core.indexers.objects import (
BaseIndexer,
Expand Down
8 changes: 8 additions & 0 deletions pandas/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,11 @@ class InvalidIndexError(Exception):

.. versionadded:: 1.1.0
"""


class DataError(Exception):
"""
Exception raised when trying to perform a ohlc on a non-numnerical column.
Or, it can be raised when trying to apply a function to a non-numerical
column on a rolling window.
"""
1 change: 1 addition & 0 deletions pandas/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"MergeError",
"OptionError",
"NumbaUtilError",
"DataError",
],
)
def test_exception_importable(exc):
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/window/test_dtypes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import pytest

from pandas.errors import DataError

from pandas.core.dtypes.common import pandas_dtype

from pandas import (
Expand All @@ -9,7 +11,6 @@
Series,
)
import pandas._testing as tm
from pandas.core.base import DataError

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