-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DEPR: deprecate default of skipna=False in infer_dtype #24050
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2c9e2ea
DEPR: switch default of skipna-kwarg in infer_dtype to True
h-vetinari 9d2da42
Merge remote-tracking branch 'upstream/master' into infer_skipna
h-vetinari 21f7963
Change default of skipna to None & warn; add whatsnew
h-vetinari 568bfd9
Missed one
h-vetinari 4900f4b
Merge remote-tracking branch 'upstream/master' into infer_skipna
h-vetinari 8c3c5b4
Review (jreback)
h-vetinari 698b0d0
Merge remote-tracking branch 'upstream/master' into infer_skipna
h-vetinari 52616b0
Fix new occurrence of infer_dtype
h-vetinari d72dbda
Merge remote-tracking branch 'upstream/master' into infer_skipna
h-vetinari 245b7bc
Fix overlooked merge artefact
h-vetinari 4d97ce8
Merge remote-tracking branch 'upstream/master' into infer_skipna
h-vetinari 18e7bc6
Merge remote-tracking branch 'upstream/master' into infer_skipna
h-vetinari 72ba292
Oversight
h-vetinari ebd1063
Add kwarg to new call-sites
h-vetinari e287bd8
and another new call-site
h-vetinari 1ea21fe
Try skipna=True for new call-sites
h-vetinari fd8c010
Revert skipna=True where it was added
h-vetinari 1edd0e9
Review (jreback)
h-vetinari 03c46cd
Merge remote-tracking branch 'upstream/master' into infer_skipna
h-vetinari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,11 +334,11 @@ def test_infer_dtype_bytes(self): | |
|
||
# string array of bytes | ||
arr = np.array(list('abc'), dtype='S1') | ||
assert lib.infer_dtype(arr, skipna=False) == compare | ||
assert lib.infer_dtype(arr, skipna=True) == compare | ||
|
||
# object array of bytes | ||
arr = arr.astype(object) | ||
assert lib.infer_dtype(arr, skipna=False) == compare | ||
assert lib.infer_dtype(arr, skipna=True) == compare | ||
|
||
# object array of bytes with missing values | ||
assert lib.infer_dtype([b'a', np.nan, b'c'], skipna=True) == compare | ||
|
@@ -538,32 +538,39 @@ def test_length_zero(self, skipna): | |
|
||
def test_integers(self): | ||
arr = np.array([1, 2, 3, np.int64(4), np.int32(5)], dtype='O') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'integer' | ||
|
||
arr = np.array([1, 2, 3, np.int64(4), np.int32(5), 'foo'], dtype='O') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'mixed-integer' | ||
|
||
arr = np.array([1, 2, 3, 4, 5], dtype='i4') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'integer' | ||
|
||
def test_warn(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to test_deprecation & add the issue number as a comment |
||
arr = np.array([1, 2, 3], dtype=object) | ||
|
||
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): | ||
result = lib.infer_dtype(arr) # default: skipna=None -> warn | ||
assert result == 'integer' | ||
|
||
def test_bools(self): | ||
arr = np.array([True, False, True, True, True], dtype='O') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'boolean' | ||
|
||
arr = np.array([np.bool_(True), np.bool_(False)], dtype='O') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'boolean' | ||
|
||
arr = np.array([True, False, True, 'foo'], dtype='O') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'mixed' | ||
|
||
arr = np.array([True, False, True], dtype=bool) | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'boolean' | ||
|
||
arr = np.array([True, np.nan, False], dtype='O') | ||
|
@@ -575,38 +582,38 @@ def test_bools(self): | |
|
||
def test_floats(self): | ||
arr = np.array([1., 2., 3., np.float64(4), np.float32(5)], dtype='O') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'floating' | ||
|
||
arr = np.array([1, 2, 3, np.float64(4), np.float32(5), 'foo'], | ||
dtype='O') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'mixed-integer' | ||
|
||
arr = np.array([1, 2, 3, 4, 5], dtype='f4') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'floating' | ||
|
||
arr = np.array([1, 2, 3, 4, 5], dtype='f8') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'floating' | ||
|
||
def test_decimals(self): | ||
# GH15690 | ||
arr = np.array([Decimal(1), Decimal(2), Decimal(3)]) | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'decimal' | ||
|
||
arr = np.array([1.0, 2.0, Decimal(3)]) | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'mixed' | ||
|
||
arr = np.array([Decimal(1), Decimal('NaN'), Decimal(3)]) | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'decimal' | ||
|
||
arr = np.array([Decimal(1), np.nan, Decimal(3)], dtype='O') | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'decimal' | ||
|
||
def test_string(self): | ||
|
@@ -648,34 +655,34 @@ def test_infer_dtype_datetime(self): | |
|
||
arr = np.array([Timestamp('2011-01-01'), | ||
Timestamp('2011-01-02')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'datetime' | ||
assert lib.infer_dtype(arr, skipna=True) == 'datetime' | ||
|
||
arr = np.array([np.datetime64('2011-01-01'), | ||
np.datetime64('2011-01-01')], dtype=object) | ||
assert lib.infer_dtype(arr, skipna=False) == 'datetime64' | ||
assert lib.infer_dtype(arr, skipna=True) == 'datetime64' | ||
|
||
arr = np.array([datetime(2011, 1, 1), datetime(2012, 2, 1)]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'datetime' | ||
assert lib.infer_dtype(arr, skipna=True) == 'datetime' | ||
|
||
# starts with nan | ||
for n in [pd.NaT, np.nan]: | ||
arr = np.array([n, pd.Timestamp('2011-01-02')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'datetime' | ||
assert lib.infer_dtype(arr, skipna=True) == 'datetime' | ||
|
||
arr = np.array([n, np.datetime64('2011-01-02')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'datetime64' | ||
assert lib.infer_dtype(arr, skipna=True) == 'datetime64' | ||
|
||
arr = np.array([n, datetime(2011, 1, 1)]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'datetime' | ||
assert lib.infer_dtype(arr, skipna=True) == 'datetime' | ||
|
||
arr = np.array([n, pd.Timestamp('2011-01-02'), n]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'datetime' | ||
assert lib.infer_dtype(arr, skipna=True) == 'datetime' | ||
|
||
arr = np.array([n, np.datetime64('2011-01-02'), n]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'datetime64' | ||
assert lib.infer_dtype(arr, skipna=True) == 'datetime64' | ||
|
||
arr = np.array([n, datetime(2011, 1, 1), n]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'datetime' | ||
assert lib.infer_dtype(arr, skipna=True) == 'datetime' | ||
|
||
# different type of nat | ||
arr = np.array([np.timedelta64('nat'), | ||
|
@@ -689,58 +696,58 @@ def test_infer_dtype_datetime(self): | |
# mixed datetime | ||
arr = np.array([datetime(2011, 1, 1), | ||
pd.Timestamp('2011-01-02')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'datetime' | ||
assert lib.infer_dtype(arr, skipna=True) == 'datetime' | ||
|
||
# should be datetime? | ||
arr = np.array([np.datetime64('2011-01-01'), | ||
pd.Timestamp('2011-01-02')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'mixed' | ||
assert lib.infer_dtype(arr, skipna=True) == 'mixed' | ||
|
||
arr = np.array([pd.Timestamp('2011-01-02'), | ||
np.datetime64('2011-01-01')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'mixed' | ||
assert lib.infer_dtype(arr, skipna=True) == 'mixed' | ||
|
||
arr = np.array([np.nan, pd.Timestamp('2011-01-02'), 1]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'mixed-integer' | ||
assert lib.infer_dtype(arr, skipna=True) == 'mixed-integer' | ||
|
||
arr = np.array([np.nan, pd.Timestamp('2011-01-02'), 1.1]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'mixed' | ||
assert lib.infer_dtype(arr, skipna=True) == 'mixed' | ||
|
||
arr = np.array([np.nan, '2011-01-01', pd.Timestamp('2011-01-02')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'mixed' | ||
assert lib.infer_dtype(arr, skipna=True) == 'mixed' | ||
|
||
def test_infer_dtype_timedelta(self): | ||
|
||
arr = np.array([pd.Timedelta('1 days'), | ||
pd.Timedelta('2 days')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'timedelta' | ||
assert lib.infer_dtype(arr, skipna=True) == 'timedelta' | ||
|
||
arr = np.array([np.timedelta64(1, 'D'), | ||
np.timedelta64(2, 'D')], dtype=object) | ||
assert lib.infer_dtype(arr, skipna=False) == 'timedelta' | ||
assert lib.infer_dtype(arr, skipna=True) == 'timedelta' | ||
|
||
arr = np.array([timedelta(1), timedelta(2)]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'timedelta' | ||
assert lib.infer_dtype(arr, skipna=True) == 'timedelta' | ||
|
||
# starts with nan | ||
for n in [pd.NaT, np.nan]: | ||
arr = np.array([n, Timedelta('1 days')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'timedelta' | ||
assert lib.infer_dtype(arr, skipna=True) == 'timedelta' | ||
|
||
arr = np.array([n, np.timedelta64(1, 'D')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'timedelta' | ||
assert lib.infer_dtype(arr, skipna=True) == 'timedelta' | ||
|
||
arr = np.array([n, timedelta(1)]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'timedelta' | ||
assert lib.infer_dtype(arr, skipna=True) == 'timedelta' | ||
|
||
arr = np.array([n, pd.Timedelta('1 days'), n]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'timedelta' | ||
assert lib.infer_dtype(arr, skipna=True) == 'timedelta' | ||
|
||
arr = np.array([n, np.timedelta64(1, 'D'), n]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'timedelta' | ||
assert lib.infer_dtype(arr, skipna=True) == 'timedelta' | ||
|
||
arr = np.array([n, timedelta(1), n]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'timedelta' | ||
assert lib.infer_dtype(arr, skipna=True) == 'timedelta' | ||
|
||
# different type of nat | ||
arr = np.array([np.datetime64('nat'), np.timedelta64(1, 'D')], | ||
|
@@ -755,19 +762,19 @@ def test_infer_dtype_period(self): | |
# GH 13664 | ||
arr = np.array([pd.Period('2011-01', freq='D'), | ||
pd.Period('2011-02', freq='D')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'period' | ||
assert lib.infer_dtype(arr, skipna=True) == 'period' | ||
|
||
arr = np.array([pd.Period('2011-01', freq='D'), | ||
pd.Period('2011-02', freq='M')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'period' | ||
assert lib.infer_dtype(arr, skipna=True) == 'period' | ||
|
||
# starts with nan | ||
for n in [pd.NaT, np.nan]: | ||
arr = np.array([n, pd.Period('2011-01', freq='D')]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'period' | ||
assert lib.infer_dtype(arr, skipna=True) == 'period' | ||
|
||
arr = np.array([n, pd.Period('2011-01', freq='D'), n]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'period' | ||
assert lib.infer_dtype(arr, skipna=True) == 'period' | ||
|
||
# different type of nat | ||
arr = np.array([np.datetime64('nat'), pd.Period('2011-01', freq='M')], | ||
|
@@ -846,7 +853,7 @@ def test_infer_datetimelike_array_nan_nat_like(self, first, second, | |
|
||
def test_infer_dtype_all_nan_nat_like(self): | ||
arr = np.array([np.nan, np.nan]) | ||
assert lib.infer_dtype(arr, skipna=False) == 'floating' | ||
assert lib.infer_dtype(arr, skipna=True) == 'floating' | ||
|
||
# nan and None mix are result in mixed | ||
arr = np.array([np.nan, np.nan, None]) | ||
|
@@ -1043,17 +1050,17 @@ def test_categorical(self): | |
# GH 8974 | ||
from pandas import Categorical, Series | ||
arr = Categorical(list('abc')) | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'categorical' | ||
|
||
result = lib.infer_dtype(Series(arr), skipna=False) | ||
result = lib.infer_dtype(Series(arr), skipna=True) | ||
assert result == 'categorical' | ||
|
||
arr = Categorical(list('abc'), categories=['cegfab'], ordered=True) | ||
result = lib.infer_dtype(arr, skipna=False) | ||
result = lib.infer_dtype(arr, skipna=True) | ||
assert result == 'categorical' | ||
|
||
result = lib.infer_dtype(Series(arr), skipna=False) | ||
result = lib.infer_dtype(Series(arr), skipna=True) | ||
assert result == 'categorical' | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.