-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: np.inf now causes Index to upcast from int to float #16996
Changes from 1 commit
b424439
f040f4e
6f3886f
e029708
61d82f6
5de878f
7310c36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,8 +75,7 @@ def test_inf_upcast(self): | |
df.loc[np.inf] = 3 | ||
|
||
# make sure we can look up the value | ||
result = df.loc[np.inf, 0] | ||
tm.assert_almost_equal(result, 3) | ||
assert df.loc[np.inf, 0] == 3 | ||
|
||
result = df.index | ||
expected = pd.Float64Index([1, 2, np.inf]) | ||
|
@@ -571,17 +570,23 @@ def test_astype_assignment_with_dups(self): | |
# result = df.get_dtype_counts().sort_index() | ||
# expected = Series({'float64': 2, 'object': 1}).sort_index() | ||
|
||
def test_coercion_with_contains(self): | ||
@pytest.mark.parametrize("val,expected", [ | ||
(np.inf, False), | ||
(np.nan, False), | ||
(3.0, True), | ||
(3.5, False), | ||
(0.0, True), | ||
]) | ||
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. Nice! Lots of good test cases. However, I'd like to split these in two tests based on the expected result. This is because statements like "assert result is True" are less idiomatic. Rather, we should be saying "assert val in index" OR "assert val not in index." It also means one fewer parameter in your |
||
def test_coercion_with_contains(self, val, expected): | ||
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. Not quite what I was going for here. What I actually was asking you to do was create example indices that contain 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. Ah, I guess I didn't understand that because I was explicitly using a 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. Yes, you can by all means use |
||
# Related to GH 16957 | ||
# Checking if Int64Index contains np.inf should catch the OverflowError | ||
for val in [np.inf, np.nan]: | ||
index = pd.Int64Index([1, 2, 3]) | ||
result = val in index | ||
tm.assert_almost_equal(result, False) | ||
|
||
index = pd.UInt64Index([1, 2, 3]) | ||
result = np.inf in index | ||
tm.assert_almost_equal(result, False) | ||
index = pd.Int64Index([1, 2, 3]) | ||
result = val in index | ||
assert result is expected | ||
|
||
index = pd.UInt64Index([1, 2, 3]) | ||
result = val in index | ||
assert result is expected | ||
|
||
def test_index_type_coercion(self): | ||
|
||
|
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.
use double-backticks on
np.inf
andOverflowError