-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Adjust Series specific tests for string option #55538
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
Changes from 15 commits
9e9f567
23595ab
f3bb720
2c8de1b
3b5e7e7
b613e5a
93ee4d7
c0f629f
43a27a1
224b7f6
8cf3af5
e49c77b
f32ef80
f546925
3d24dc2
75f1ae1
ec54b76
f93f01b
07336dd
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 |
---|---|---|
|
@@ -71,7 +71,7 @@ def test_getitem_unrecognized_scalar(self): | |
def test_getitem_negative_out_of_bounds(self): | ||
ser = Series(["a"] * 10, index=["a"] * 10) | ||
|
||
msg = "index -11 is out of bounds for axis 0 with size 10" | ||
msg = "index -11 is out of bounds for axis 0 with size 10|index out of bounds" | ||
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. can you use a "|".join pattern 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. I don't feel super strong here but I prefer the pipe pattern for 2 options |
||
warn_msg = "Series.__getitem__ treating keys as positions is deprecated" | ||
with pytest.raises(IndexError, match=msg): | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
|
@@ -363,7 +363,9 @@ def test_getitem_no_matches(self, box): | |
key = Series(["C"], dtype=object) | ||
key = box(key) | ||
|
||
msg = r"None of \[Index\(\['C'\], dtype='object'\)\] are in the \[index\]" | ||
msg = ( | ||
r"None of \[Index\(\['C'\], dtype='object|string'\)\] are in the \[index\]" | ||
) | ||
with pytest.raises(KeyError, match=msg): | ||
ser[key] | ||
|
||
|
@@ -437,7 +439,7 @@ def test_getitem_boolean_empty(self): | |
|
||
# GH#5877 | ||
# indexing with empty series | ||
ser = Series(["A", "B"]) | ||
ser = Series(["A", "B"], dtype=object) | ||
expected = Series(dtype=object, index=Index([], dtype="int64")) | ||
result = ser[Series([], dtype=object)] | ||
tm.assert_series_equal(result, expected) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
date, | ||
datetime, | ||
) | ||
from decimal import Decimal | ||
|
||
import numpy as np | ||
import pytest | ||
|
@@ -175,7 +176,8 @@ class TestSetitemScalarIndexer: | |
def test_setitem_negative_out_of_bounds(self): | ||
ser = Series(["a"] * 10, index=["a"] * 10) | ||
|
||
msg = "index -11 is out of bounds for axis 0 with size 10" | ||
# string index falls back to positional | ||
msg = "index -11|-1 is out of bounds for axis 0 with size 10" | ||
warn_msg = "Series.__setitem__ treating keys as positions is deprecated" | ||
with pytest.raises(IndexError, match=msg): | ||
with tm.assert_produces_warning(FutureWarning, match=warn_msg): | ||
|
@@ -527,14 +529,17 @@ def test_setitem_empty_series_timestamp_preserves_dtype(self): | |
Timedelta("9 days").to_pytimedelta(), | ||
], | ||
) | ||
def test_append_timedelta_does_not_cast(self, td): | ||
def test_append_timedelta_does_not_cast(self, td, using_infer_string): | ||
# GH#22717 inserting a Timedelta should _not_ cast to int64 | ||
expected = Series(["x", td], index=[0, "td"], dtype=object) | ||
|
||
ser = Series(["x"]) | ||
ser["td"] = td | ||
tm.assert_series_equal(ser, expected) | ||
assert isinstance(ser["td"], Timedelta) | ||
if using_infer_string and not isinstance(td, Timedelta): | ||
assert not isinstance(ser["td"], Timedelta) | ||
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. What would 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. one of those 2:
maybe we should xfail that test, not sure anymore what my reasoning here was 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. Yeah I find it weird to begin with that this always promoted timedeltas to Agree to xfail this test for now to nail down the correct behavior in a follow up |
||
else: | ||
assert isinstance(ser["td"], Timedelta) | ||
|
||
ser = Series(["x"]) | ||
ser.loc["td"] = Timedelta("9 days") | ||
|
@@ -595,13 +600,21 @@ def test_setitem_enlarge_with_na( | |
expected = Series(expected_values, dtype=target_dtype) | ||
tm.assert_series_equal(ser, expected) | ||
|
||
def test_setitem_enlargement_object_none(self, nulls_fixture): | ||
def test_setitem_enlargement_object_none(self, nulls_fixture, using_infer_string): | ||
# GH#48665 | ||
ser = Series(["a", "b"]) | ||
ser[3] = nulls_fixture | ||
expected = Series(["a", "b", nulls_fixture], index=[0, 1, 3]) | ||
dtype = ( | ||
"string[pyarrow_numpy]" | ||
if using_infer_string and not isinstance(nulls_fixture, Decimal) | ||
else object | ||
) | ||
expected = Series(["a", "b", nulls_fixture], index=[0, 1, 3], dtype=dtype) | ||
tm.assert_series_equal(ser, expected) | ||
assert ser[3] is nulls_fixture | ||
if using_infer_string: | ||
ser[3] is np.nan | ||
else: | ||
assert ser[3] is nulls_fixture | ||
|
||
|
||
def test_setitem_scalar_into_readonly_backing_data(): | ||
|
@@ -845,20 +858,28 @@ def test_series_where(self, obj, key, expected, warn, val, is_inplace): | |
|
||
self._check_inplace(is_inplace, orig, arr, obj) | ||
|
||
def test_index_where(self, obj, key, expected, warn, val): | ||
def test_index_where(self, obj, key, expected, warn, val, using_infer_string): | ||
mask = np.zeros(obj.shape, dtype=bool) | ||
mask[key] = True | ||
|
||
res = Index(obj).where(~mask, val) | ||
expected_idx = Index(expected, dtype=expected.dtype) | ||
tm.assert_index_equal(res, expected_idx) | ||
if using_infer_string and obj.dtype == object: | ||
with pytest.raises(TypeError, match="Scalar must"): | ||
Index(obj).where(~mask, val) | ||
else: | ||
res = Index(obj).where(~mask, val) | ||
expected_idx = Index(expected, dtype=expected.dtype) | ||
tm.assert_index_equal(res, expected_idx) | ||
|
||
def test_index_putmask(self, obj, key, expected, warn, val): | ||
def test_index_putmask(self, obj, key, expected, warn, val, using_infer_string): | ||
mask = np.zeros(obj.shape, dtype=bool) | ||
mask[key] = True | ||
|
||
res = Index(obj).putmask(mask, val) | ||
tm.assert_index_equal(res, Index(expected, dtype=expected.dtype)) | ||
if using_infer_string and obj.dtype == object: | ||
with pytest.raises(TypeError, match="Scalar must"): | ||
Index(obj).putmask(mask, val) | ||
else: | ||
res = Index(obj).putmask(mask, val) | ||
tm.assert_index_equal(res, Index(expected, dtype=expected.dtype)) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
Uh oh!
There was an error while loading. Please reload this page.