-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
COMPAT: sum/prod on all nan will remain nan regardless of bottleneck install #17630
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 all commits
Commits
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 |
---|---|---|
|
@@ -448,7 +448,11 @@ def test_sum(self): | |
has_numeric_only=True, check_dtype=False, | ||
check_less_precise=True) | ||
|
||
def test_stat_operators_attempt_obj_array(self): | ||
@pytest.mark.parametrize( | ||
"method", ['sum', 'mean', 'prod', 'var', | ||
'std', 'skew', 'min', 'max']) | ||
def test_stat_operators_attempt_obj_array(self, method): | ||
# GH #676 | ||
data = { | ||
'a': [-0.00049987540199591344, -0.0016467257772919831, | ||
0.00067695870775883013], | ||
|
@@ -458,20 +462,17 @@ def test_stat_operators_attempt_obj_array(self): | |
} | ||
df1 = DataFrame(data, index=['foo', 'bar', 'baz'], | ||
dtype='O') | ||
methods = ['sum', 'mean', 'prod', 'var', 'std', 'skew', 'min', 'max'] | ||
|
||
# GH #676 | ||
df2 = DataFrame({0: [np.nan, 2], 1: [np.nan, 3], | ||
2: [np.nan, 4]}, dtype=object) | ||
|
||
for df in [df1, df2]: | ||
for meth in methods: | ||
assert df.values.dtype == np.object_ | ||
result = getattr(df, meth)(1) | ||
expected = getattr(df.astype('f8'), meth)(1) | ||
assert df.values.dtype == np.object_ | ||
result = getattr(df, method)(1) | ||
expected = getattr(df.astype('f8'), method)(1) | ||
|
||
if not tm._incompat_bottleneck_version(meth): | ||
tm.assert_series_equal(result, expected) | ||
if method in ['sum', 'prod']: | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_mean(self): | ||
self._check_stat_op('mean', np.mean, check_dates=True) | ||
|
@@ -563,15 +564,15 @@ def test_var_std(self): | |
arr = np.repeat(np.random.random((1, 1000)), 1000, 0) | ||
result = nanops.nanvar(arr, axis=0) | ||
assert not (result < 0).any() | ||
if nanops._USE_BOTTLENECK: | ||
nanops._USE_BOTTLENECK = False | ||
|
||
with pd.option_context('use_bottleneck', False): | ||
result = nanops.nanvar(arr, axis=0) | ||
assert not (result < 0).any() | ||
nanops._USE_BOTTLENECK = True | ||
|
||
def test_numeric_only_flag(self): | ||
@pytest.mark.parametrize( | ||
"meth", ['sem', 'var', 'std']) | ||
def test_numeric_only_flag(self, meth): | ||
# GH #9201 | ||
methods = ['sem', 'var', 'std'] | ||
df1 = DataFrame(np.random.randn(5, 3), columns=['foo', 'bar', 'baz']) | ||
# set one entry to a number in str format | ||
df1.loc[0, 'foo'] = '100' | ||
|
@@ -580,20 +581,19 @@ def test_numeric_only_flag(self): | |
# set one entry to a non-number str | ||
df2.loc[0, 'foo'] = 'a' | ||
|
||
for meth in methods: | ||
result = getattr(df1, meth)(axis=1, numeric_only=True) | ||
expected = getattr(df1[['bar', 'baz']], meth)(axis=1) | ||
tm.assert_series_equal(expected, result) | ||
result = getattr(df1, meth)(axis=1, numeric_only=True) | ||
expected = getattr(df1[['bar', 'baz']], meth)(axis=1) | ||
tm.assert_series_equal(expected, result) | ||
|
||
result = getattr(df2, meth)(axis=1, numeric_only=True) | ||
expected = getattr(df2[['bar', 'baz']], meth)(axis=1) | ||
tm.assert_series_equal(expected, result) | ||
result = getattr(df2, meth)(axis=1, numeric_only=True) | ||
expected = getattr(df2[['bar', 'baz']], meth)(axis=1) | ||
tm.assert_series_equal(expected, result) | ||
|
||
# df1 has all numbers, df2 has a letter inside | ||
pytest.raises(TypeError, lambda: getattr(df1, meth)( | ||
axis=1, numeric_only=False)) | ||
pytest.raises(TypeError, lambda: getattr(df2, meth)( | ||
axis=1, numeric_only=False)) | ||
# df1 has all numbers, df2 has a letter inside | ||
pytest.raises(TypeError, lambda: getattr(df1, meth)( | ||
axis=1, numeric_only=False)) | ||
pytest.raises(TypeError, lambda: getattr(df2, meth)( | ||
axis=1, numeric_only=False)) | ||
|
||
def test_mixed_ops(self): | ||
# GH 16116 | ||
|
@@ -606,11 +606,9 @@ def test_mixed_ops(self): | |
result = getattr(df, op)() | ||
assert len(result) == 2 | ||
|
||
if nanops._USE_BOTTLENECK: | ||
nanops._USE_BOTTLENECK = False | ||
with pd.option_context('use_bottleneck', False): | ||
result = getattr(df, op)() | ||
assert len(result) == 2 | ||
nanops._USE_BOTTLENECK = True | ||
|
||
def test_cumsum(self): | ||
self.tsframe.loc[5:10, 0] = nan | ||
|
@@ -676,11 +674,10 @@ def test_sem(self): | |
arr = np.repeat(np.random.random((1, 1000)), 1000, 0) | ||
result = nanops.nansem(arr, axis=0) | ||
assert not (result < 0).any() | ||
if nanops._USE_BOTTLENECK: | ||
nanops._USE_BOTTLENECK = False | ||
|
||
with pd.option_context('use_bottleneck', False): | ||
result = nanops.nansem(arr, axis=0) | ||
assert not (result < 0).any() | ||
nanops._USE_BOTTLENECK = True | ||
|
||
def test_skew(self): | ||
tm._skip_if_no_scipy() | ||
|
@@ -767,7 +764,7 @@ def wrapper(x): | |
tm.assert_series_equal(result0, frame.apply(skipna_wrapper), | ||
check_dtype=check_dtype, | ||
check_less_precise=check_less_precise) | ||
if not tm._incompat_bottleneck_version(name): | ||
if name in ['sum', 'prod']: | ||
exp = frame.apply(skipna_wrapper, axis=1) | ||
tm.assert_series_equal(result1, exp, check_dtype=False, | ||
check_less_precise=check_less_precise) | ||
|
@@ -799,7 +796,7 @@ def wrapper(x): | |
all_na = self.frame * np.NaN | ||
r0 = getattr(all_na, name)(axis=0) | ||
r1 = getattr(all_na, name)(axis=1) | ||
if not tm._incompat_bottleneck_version(name): | ||
if name in ['sum', 'prod']: | ||
assert np.isnan(r0).all() | ||
assert np.isnan(r1).all() | ||
|
||
|
@@ -1859,14 +1856,14 @@ def test_dataframe_clip(self): | |
assert (clipped_df.values[ub_mask] == ub).all() | ||
assert (clipped_df.values[mask] == df.values[mask]).all() | ||
|
||
@pytest.mark.xfail(reason=("clip on mixed integer or floats " | ||
"with integer clippers coerces to float")) | ||
def test_clip_mixed_numeric(self): | ||
|
||
# TODO(jreback) | ||
# clip on mixed integer or floats | ||
# with integer clippers coerces to float | ||
df = DataFrame({'A': [1, 2, 3], | ||
'B': [1., np.nan, 3.]}) | ||
result = df.clip(1, 2) | ||
expected = DataFrame({'A': [1, 2, 2], | ||
expected = DataFrame({'A': [1, 2, 2.], | ||
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. is this related ? 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. no I think was un-xfailing a test and that's all it needed IIRC. |
||
'B': [1., np.nan, 2.]}) | ||
tm.assert_frame_equal(result, expected, check_like=True) | ||
|
||
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe state that it always returns
NaN
.