Skip to content

Commit

Permalink
DEPR: infer_dtype default for skipna is now True (#29876)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jorisvandenbossche committed Nov 28, 2019
1 parent 930b52a commit 20ff599
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
14 changes: 3 additions & 11 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ from fractions import Fraction
from numbers import Number

import sys
import warnings

import cython
from cython import Py_ssize_t
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1094,15 +1093,15 @@ 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.

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
Expand All @@ -1113,7 +1112,6 @@ def infer_dtype(value: object, skipna: object=None) -> str:
Results can include:

- string
- unicode
- bytes
- floating
- integer
Expand Down Expand Up @@ -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'):
Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 20ff599

Please sign in to comment.