Skip to content

API: infer_dtype with skipna=True only skip valid-for-dtype NAs #45022

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

Closed
jbrockmendel opened this issue Dec 23, 2021 · 1 comment · Fixed by #45057
Closed

API: infer_dtype with skipna=True only skip valid-for-dtype NAs #45022

jbrockmendel opened this issue Dec 23, 2021 · 1 comment · Fixed by #45057
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Dec 23, 2021

I'm working on making lib.infer_dtype copy-free and finding things would be easier/more consistent if we tweaked the meaning of the skipna keyword.

In particular, instead of doing values = values[~isnaobj(values)], followed by e.g. is_string_array(values), we could do is_string_array(values, skipna=skipna). This would change the results in cases where we have NA values that are not considered valid_na by is_string_array, e.g. in the status quo:

import pandas as pd
import numpy as np
from pandas._libs import lib

arr = np.array(["foo", pd.NaT, "bar"], dtype=object)

In [2]: lib.infer_dtype(arr, skipna=True)
Out[2]: 'string'

In [3]: lib.is_string_array(arr, skipna=True)
Out[3]: False

So the suggestion here is to change [2] to give 'mixed'. I'm finding that to make this work without breaking the world we also need to change StringValidator.is_valid_null to accept np.nan and None (currently just accepts pd.NA)

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 23, 2021
@jbrockmendel
Copy link
Member Author

xref #40839 the inconsistency between StringArray and pd.array on np.array(['a', np.nan, 'b'], dtype=object) is one of the last sticking points on implementing this.

@mroeschke mroeschke added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 27, 2021
@jreback jreback added this to the 1.5 milestone Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants