diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index d01a5fb4f8b43..ca950fbe047d9 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:`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/_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..53e979d12a56d 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -628,13 +628,13 @@ def test_integer_na(self, arr, skipna): expected = "integer" if skipna else "integer-na" assert result == expected - def test_deprecation(self): - # GH 24050 - arr = np.array([1, 2, 3], dtype=object) + 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) - 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")