From aaf72c2533b875d118c29b5d9f2bcd62b3d9546a Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 26 Nov 2019 18:34:49 -0800 Subject: [PATCH 1/2] DEPR: infer_dtype default for skipna is now True --- doc/source/whatsnew/v1.0.0.rst | 1 + pandas/_libs/lib.pyx | 14 +++----------- pandas/tests/dtypes/test_inference.py | 9 ++++----- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 48808a7ef7a46..089a82eadf536 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -402,6 +402,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. **Other removals** - Floordiv of integer-dtyped array by :class:`Timedelta` now raises ``TypeError`` (:issue:`21036`) +- :func:`_libs.lib.infer_dtype` argument ``skipna`` defaults to ``True`` instead of ``False`` (:issue:`24050`) - Removed the previously deprecated :meth:`Index.summary` (:issue:`18217`) - Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`) - Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index aaf6456df8f8e..780f93291cee8 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -4,7 +4,6 @@ from fractions import Fraction from numbers import Number import sys -import warnings import cython from cython import Py_ssize_t @@ -615,7 +614,7 @@ def clean_index_list(obj: list): # don't force numpy coerce with nan's inferred = infer_dtype(obj, skipna=False) - if inferred in ['string', 'bytes', 'unicode', 'mixed', 'mixed-integer']: + if inferred in ['string', 'bytes', 'mixed', 'mixed-integer']: return np.asarray(obj, dtype=object), 0 elif inferred in ['integer']: # TODO: we infer an integer but it *could* be a uint64 @@ -1094,7 +1093,7 @@ cdef _try_infer_map(v): return None -def infer_dtype(value: object, skipna: object=None) -> str: +def infer_dtype(value: object, skipna: bool = True) -> str: """ Efficiently infer the type of a passed val, or list-like array of values. Return a string describing the type. @@ -1102,7 +1101,7 @@ def infer_dtype(value: object, skipna: object=None) -> str: Parameters ---------- value : scalar, list, ndarray, or pandas type - skipna : bool, default False + skipna : bool, default True Ignore NaN values when inferring the type. .. versionadded:: 0.21.0 @@ -1113,7 +1112,6 @@ def infer_dtype(value: object, skipna: object=None) -> str: Results can include: - string - - unicode - bytes - floating - integer @@ -1200,12 +1198,6 @@ def infer_dtype(value: object, skipna: object=None) -> str: bint seen_pdnat = False bint seen_val = False - if skipna is None: - msg = ('A future version of pandas will default to `skipna=True`. To ' - 'silence this warning, pass `skipna=True|False` explicitly.') - warnings.warn(msg, FutureWarning, stacklevel=2) - skipna = False - if util.is_array(value): values = value elif hasattr(value, 'dtype'): diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 743b844917edf..2b492e2944c4e 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -629,12 +629,11 @@ def test_integer_na(self, arr, skipna): assert result == expected def test_deprecation(self): - # GH 24050 - arr = np.array([1, 2, 3], dtype=object) + # GH 24050, enforced GH#???? skipna defaultt is not True + arr = np.array([1, 2, 3, np.nan], dtype=object) - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = lib.infer_dtype(arr) # default: skipna=None -> warn - assert result == "integer" + result = lib.infer_dtype(arr) + assert result == "integer" def test_bools(self): arr = np.array([True, False, True, True, True], dtype="O") From f44e3ad42cb81c8978860c10d42d6280426593c8 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 27 Nov 2019 13:37:28 -0800 Subject: [PATCH 2/2] suggested edits --- doc/source/whatsnew/v1.0.0.rst | 2 +- pandas/tests/dtypes/test_inference.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 3200c94e050e0..ca950fbe047d9 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -402,7 +402,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. **Other removals** - Floordiv of integer-dtyped array by :class:`Timedelta` now raises ``TypeError`` (:issue:`21036`) -- :func:`_libs.lib.infer_dtype` argument ``skipna`` defaults to ``True`` instead of ``False`` (:issue:`24050`) +- :func:`pandas.api.types.infer_dtype` argument ``skipna`` defaults to ``True`` instead of ``False`` (:issue:`24050`) - Removed the previously deprecated :meth:`Index.summary` (:issue:`18217`) - Removed the previously deprecated "fastpath" keyword from the :class:`Index` constructor (:issue:`23110`) - Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 2b492e2944c4e..53e979d12a56d 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -628,8 +628,9 @@ def test_integer_na(self, arr, skipna): expected = "integer" if skipna else "integer-na" assert result == expected - def test_deprecation(self): - # GH 24050, enforced GH#???? skipna defaultt is not True + def test_infer_dtype_skipna_default(self): + # infer_dtype `skipna` default deprecated in GH#24050, + # changed to True in GH#29876 arr = np.array([1, 2, 3, np.nan], dtype=object) result = lib.infer_dtype(arr)