From 4bead6f7e3ec0b4aaa47f4b57ee54436594ae877 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Tue, 18 Jul 2017 07:07:48 -0400 Subject: [PATCH] deprecate isnull/notnull --- pandas/core/categorical.py | 8 ++++---- pandas/core/dtypes/missing.py | 13 ++++++++++--- pandas/core/generic.py | 7 ++++--- pandas/core/indexes/base.py | 8 ++++---- pandas/core/sparse/frame.py | 6 +++--- pandas/core/sparse/series.py | 5 +++-- pandas/util/__init__.py | 2 +- pandas/util/_decorators.py | 22 ++++++++++++++++++++-- 8 files changed, 49 insertions(+), 22 deletions(-) diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py index 3810455521a65c..79ab25266770a4 100644 --- a/pandas/core/categorical.py +++ b/pandas/core/categorical.py @@ -34,8 +34,8 @@ import pandas.core.common as com from pandas.core.missing import interpolate_2d from pandas.compat.numpy import function as nv -from pandas.util._decorators import (Appender, cache_readonly, - deprecate_kwarg, Substitution) +from pandas.util._decorators import ( + Appender, cache_readonly, deprecate_kwarg, deprecate, Substitution) from pandas.io.formats.terminal import get_terminal_size from pandas.util._validators import validate_bool_kwarg @@ -1179,7 +1179,7 @@ def isna(self): # we only have one NA in categories ret = np.logical_or(ret, self._codes == nan_pos) return ret - isull = isna + isnull = deprecate('isna', isna, klass=DeprecationWarning) def notna(self): """ @@ -1199,7 +1199,7 @@ def notna(self): """ return ~self.isna() - notnull = notna + notnull = deprecate('notna', notna, klass=DeprecationWarning) def put(self, *args, **kwargs): """ diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index 45b8af6277c4c0..2932218c5dd86b 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -1,6 +1,7 @@ """ missing types & inference """ +import warnings import numpy as np from pandas._libs import lib from pandas._libs.tslib import NaT, iNaT @@ -44,7 +45,10 @@ def isna(obj): return _isna(obj) -isnull = isna +def isnull(obj): + warnings.warn("isnull is deprecated. Use isna instead", + DeprecationWarning, stacklevel=2) + return isna(obj) def _isna_new(obj): @@ -213,7 +217,10 @@ def notna(obj): return ~res -notnull = notna +def notnull(obj): + warnings.warn("notnull is deprecated. Use notna instead", + DeprecationWarning, stacklevel=2) + return notna(obj) def is_null_datelike_scalar(other): @@ -406,4 +413,4 @@ def remove_na_arraylike(arr): """ Return array-like containing only true/non-NaN values, possibly empty. """ - return arr[notnull(lib.values_from_object(arr))] + return arr[notna(lib.values_from_object(arr))] diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 36ecf82ca4b1e7..b9934875a1e443 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -54,7 +54,8 @@ isidentifier, set_function_name, cPickle as pkl) from pandas.core.ops import _align_method_FRAME import pandas.core.nanops as nanops -from pandas.util._decorators import Appender, Substitution, deprecate_kwarg +from pandas.util._decorators import (Appender, Substitution, + deprecate, deprecate_kwarg) from pandas.util._validators import validate_bool_kwarg from pandas.core import config @@ -4412,7 +4413,7 @@ def asof(self, where, subset=None): @Appender(_shared_docs['isna']) def isna(self): return isna(self).__finalize__(self) - isnull = isna + isnull = deprecate('isna', isna, klass=DeprecationWarning) _shared_docs['notna'] = """ Return a boolean same-sized object indicating if the values are @@ -4426,7 +4427,7 @@ def isna(self): @Appender(_shared_docs['notna']) def notna(self): return notna(self).__finalize__(self) - notnull = notna + notnull = deprecate('notna', notna, klass=DeprecationWarning) def _clip_with_scalar(self, lower, upper, inplace=False): if ((lower is not None and np.any(isna(lower))) or diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index a2ee7b9e29a50d..0bbd71642daf39 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -41,8 +41,8 @@ from pandas.core.base import PandasObject, IndexOpsMixin import pandas.core.base as base -from pandas.util._decorators import (Appender, Substitution, - cache_readonly, deprecate_kwarg) +from pandas.util._decorators import ( + Appender, Substitution, cache_readonly, deprecate, deprecate_kwarg) from pandas.core.indexes.frozen import FrozenList import pandas.core.common as com import pandas.core.dtypes.concat as _concat @@ -1848,7 +1848,7 @@ def isna(self): pandas.isna : pandas version """ return self._isnan - isnull = isna + isnull = deprecate('isna', isna, klass=DeprecationWarning) def notna(self): """ @@ -1865,7 +1865,7 @@ def notna(self): pandas.notna : pandas version """ return ~self.isna() - notnull = notna + notnull = deprecate('notna', notna, klass=DeprecationWarning) def putmask(self, mask, value): """ diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index 9f94794b4b317a..5cf0546af2ad17 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -26,7 +26,7 @@ import pandas.core.generic as generic from pandas.core.sparse.series import SparseSeries, SparseArray from pandas._libs.sparse import BlockIndex, get_blocks -from pandas.util._decorators import Appender +from pandas.util._decorators import Appender, deprecate import pandas.core.ops as ops @@ -785,12 +785,12 @@ def cumsum(self, axis=0, *args, **kwargs): @Appender(generic._shared_docs['isna']) def isna(self): return self._apply_columns(lambda x: x.isna()) - isnull = isna + isnull = deprecate('isna', isna, klass=DeprecationWarning) @Appender(generic._shared_docs['notna']) def notna(self): return self._apply_columns(lambda x: x.notna()) - notnull = notna + notnull = deprecate('notna', notna, klass=DeprecationWarning) def apply(self, func, axis=0, broadcast=False, reduce=False): """ diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index 2c46624c025a77..a1d82f4c7931bb 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -28,6 +28,7 @@ _make_index) from pandas._libs.sparse import BlockIndex, IntIndex import pandas._libs.sparse as splib +from pandas.util._decorators import deprecate from pandas.core.sparse.scipy_sparse import ( _sparse_series_to_coo, @@ -648,7 +649,7 @@ def isna(self): sparse_index=self.values.sp_index, fill_value=isna(self.fill_value)) return self._constructor(arr, index=self.index).__finalize__(self) - isnull = isna + isnull = deprecate('isna', isna, klass=DeprecationWarning) @Appender(generic._shared_docs['notna']) def notna(self): @@ -656,7 +657,7 @@ def notna(self): sparse_index=self.values.sp_index, fill_value=notna(self.fill_value)) return self._constructor(arr, index=self.index).__finalize__(self) - notnull = notna + notnull = deprecate('notna', notna, klass=DeprecationWarning) def dropna(self, axis=0, inplace=False, **kwargs): """ diff --git a/pandas/util/__init__.py b/pandas/util/__init__.py index e86af930fef7c3..202e58c916e473 100644 --- a/pandas/util/__init__.py +++ b/pandas/util/__init__.py @@ -1,2 +1,2 @@ -from pandas.core.util.hashing import hash_pandas_object, hash_array # noqa from pandas.util._decorators import Appender, Substitution, cache_readonly # noqa +from pandas.core.util.hashing import hash_pandas_object, hash_array # noqa diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index 772b206f82e699..e406698fafe63a 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -6,12 +6,30 @@ from functools import wraps, update_wrapper -def deprecate(name, alternative, alt_name=None): +def deprecate(name, alternative, alt_name=None, klass=None, + stacklevel=2): + """ + + Return a new function that emits a deprecation warning on use + + Parameters + ---------- + name : str + Name of function to deprecate + alternative : str + Name of function to use instead + alt_name : str, optional + Name to use in preference of alternative.__name__ + klass : Warning, default FutureWarning + stacklevel : int, default 2 + + """ alt_name = alt_name or alternative.__name__ + klass = klass or FutureWarning def wrapper(*args, **kwargs): warnings.warn("%s is deprecated. Use %s instead" % (name, alt_name), - FutureWarning, stacklevel=2) + klass, stacklevel=stacklevel) return alternative(*args, **kwargs) return wrapper