Skip to content
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

DEPR: infer_dtype default for skipna is now True #29876

Merged
merged 3 commits into from
Nov 28, 2019
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
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"
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved

def test_bools(self):
arr = np.array([True, False, True, True, True], dtype="O")
Expand Down