Skip to content

DEPR: remove pandas.core.common is_* #19769

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 3 commits into from
Feb 22, 2018
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
18 changes: 18 additions & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,23 @@ Convert to an xarray DataArray

p.to_xarray()



.. _whatsnew_0230.api_breaking.core_common:

pandas.core.common removals
~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following error & warning messages are removed from ``pandas.core.common`` (:issue:`13634`, :issue:`19769`):

- ``PerformanceWarning``
- ``UnsupportedFunctionCall``
- ``UnsortedIndexError``
- ``AbstractMethodError``

These are available from import from ``pandas.errors`` (since 0.19.0).


.. _whatsnew_0230.api_breaking.apply:

Changes to make output of ``DataFrame.apply`` consistent
Expand Down Expand Up @@ -638,6 +655,7 @@ Removal of prior version deprecations/changes
- The modules `pandas.tools.hashing` and `pandas.util.hashing` have been removed (:issue:`16223`)
- The top-level functions ``pd.rolling_*``, ``pd.expanding_*`` and ``pd.ewm*`` have been removed (Deprecated since v0.18).
Instead, use the DataFrame/Series methods :attr:`~DataFrame.rolling`, :attr:`~DataFrame.expanding` and :attr:`~DataFrame.ewm` (:issue:`18723`)
- Imports from ``pandas.core.common`` for functions such as ``is_datetime64_dtype`` are now removed. These are located in ``pandas.api.types``. (:issue:`13634`, :issue:`19769`)

.. _whatsnew_0230.performance:

Expand Down
10 changes: 5 additions & 5 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
is_extension_array_dtype)

from pandas.util._validators import validate_bool_kwarg

from pandas.errors import AbstractMethodError
from pandas.core import common as com, algorithms
import pandas.core.nanops as nanops
import pandas._libs.lib as lib
Expand Down Expand Up @@ -46,7 +46,7 @@ class StringMixin(object):
# Formatting

def __unicode__(self):
raise com.AbstractMethodError(self)
raise AbstractMethodError(self)

def __str__(self):
"""
Expand Down Expand Up @@ -278,10 +278,10 @@ def _gotitem(self, key, ndim, subset=None):
subset to act on

"""
raise com.AbstractMethodError(self)
raise AbstractMethodError(self)

def aggregate(self, func, *args, **kwargs):
raise com.AbstractMethodError(self)
raise AbstractMethodError(self)

agg = aggregate

Expand Down Expand Up @@ -1252,4 +1252,4 @@ def duplicated(self, keep='first'):
# abstracts

def _update_inplace(self, result, **kwargs):
raise com.AbstractMethodError(self)
raise AbstractMethodError(self)
60 changes: 0 additions & 60 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Misc tools for implementing data structures
"""

import sys
import warnings
from datetime import datetime, timedelta
from functools import partial
import inspect
Expand All @@ -20,66 +18,8 @@
from pandas.core.dtypes.inference import _iterable_not_string
from pandas.core.dtypes.missing import isna, isnull, notnull # noqa
from pandas.api import types
from pandas.core.dtypes import common
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike

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

# back-compat of public API
# deprecate these functions
m = sys.modules['pandas.core.common']
for t in [t for t in dir(types) if not t.startswith('_')]:

def outer(t=t):

def wrapper(*args, **kwargs):
warnings.warn("pandas.core.common.{t} is deprecated. "
"import from the public API: "
"pandas.api.types.{t} instead".format(t=t),
DeprecationWarning, stacklevel=3)
return getattr(types, t)(*args, **kwargs)
return wrapper

setattr(m, t, outer(t))

# back-compat for non-public functions
# deprecate these functions
for t in ['is_datetime_arraylike',
'is_datetime_or_timedelta_dtype',
'is_datetimelike',
'is_datetimelike_v_numeric',
'is_datetimelike_v_object',
'is_datetimetz',
'is_int_or_datetime_dtype',
'is_period_arraylike',
'is_string_like',
'is_string_like_dtype']:

def outer(t=t):

def wrapper(*args, **kwargs):
warnings.warn("pandas.core.common.{t} is deprecated. "
"These are not longer public API functions, "
"but can be imported from "
"pandas.api.types.{t} instead".format(t=t),
DeprecationWarning, stacklevel=3)
return getattr(common, t)(*args, **kwargs)
return wrapper

setattr(m, t, outer(t))


# deprecate array_equivalent

def array_equivalent(*args, **kwargs):
warnings.warn("'pandas.core.common.array_equivalent' is deprecated and "
"is no longer public API", DeprecationWarning, stacklevel=2)
from pandas.core.dtypes import missing
return missing.array_equivalent(*args, **kwargs)


class SettingWithCopyError(ValueError):
pass
Expand Down
14 changes: 7 additions & 7 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.tseries.offsets import DateOffset, Tick, Day, delta_to_nanoseconds
from pandas.core.indexes.period import PeriodIndex
import pandas.core.common as com
from pandas.errors import AbstractMethodError
import pandas.core.algorithms as algos
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries

Expand Down Expand Up @@ -205,10 +205,10 @@ def __setattr__(self, attr, value):
def __getitem__(self, key):
try:
return super(Resampler, self).__getitem__(key)
except (KeyError, com.AbstractMethodError):
except (KeyError, AbstractMethodError):

# compat for deprecated
if isinstance(self.obj, com.ABCSeries):
if isinstance(self.obj, ABCSeries):
return self._deprecated('__getitem__')[key]

raise
Expand All @@ -233,7 +233,7 @@ def _convert_obj(self, obj):
return obj

def _get_binner_for_time(self):
raise com.AbstractMethodError(self)
raise AbstractMethodError(self)

def _set_binner(self):
"""
Expand Down Expand Up @@ -372,10 +372,10 @@ def transform(self, arg, *args, **kwargs):
arg, *args, **kwargs)

def _downsample(self, f):
raise com.AbstractMethodError(self)
raise AbstractMethodError(self)

def _upsample(self, f, limit=None, fill_value=None):
raise com.AbstractMethodError(self)
raise AbstractMethodError(self)

def _gotitem(self, key, ndim, subset=None):
"""
Expand Down Expand Up @@ -464,7 +464,7 @@ def _get_resampler_for_grouping(self, groupby, **kwargs):

def _wrap_result(self, result):
""" potentially wrap any results """
if isinstance(result, com.ABCSeries) and self._selection is not None:
if isinstance(result, ABCSeries) and self._selection is not None:
result.name = self._selection

if isinstance(result, ABCSeries) and result.empty:
Expand Down
38 changes: 0 additions & 38 deletions pandas/tests/api/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import pytest

from warnings import catch_warnings
import numpy as np

import pandas
from pandas.core import common as com
from pandas.api import types
from pandas.util import testing as tm

Expand Down Expand Up @@ -52,42 +50,6 @@ def check_deprecation(self, fold, fnew):
except AttributeError:
pytest.raises(AttributeError, lambda: fnew('foo'))

def test_deprecation_core_common(self):

# test that we are in fact deprecating
# the pandas.core.common introspectors
for t in self.allowed:
self.check_deprecation(getattr(com, t), getattr(types, t))

def test_deprecation_core_common_array_equivalent(self):

with tm.assert_produces_warning(DeprecationWarning):
com.array_equivalent(np.array([1, 2]), np.array([1, 2]))

def test_deprecation_core_common_moved(self):

# these are in pandas.core.dtypes.common
l = ['is_datetime_arraylike',
'is_datetime_or_timedelta_dtype',
'is_datetimelike',
'is_datetimelike_v_numeric',
'is_datetimelike_v_object',
'is_datetimetz',
'is_int_or_datetime_dtype',
'is_period_arraylike',
'is_string_like',
'is_string_like_dtype']

from pandas.core.dtypes import common as c
for t in l:
self.check_deprecation(getattr(com, t), getattr(c, t))

def test_removed_from_core_common(self):

for t in ['is_null_datelike_scalar',
'ensure_float']:
pytest.raises(AttributeError, lambda: getattr(com, t))

def test_deprecated_from_api_types(self):

for t in self.deprecated:
Expand Down