-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
DEPR: Remove special date-datetime64 case in indexing #62232
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
base: main
Are you sure you want to change the base?
Changes from all commits
bda37e8
7522828
2712fd7
8b1ab37
6e1af00
418dc4a
b60c744
2e11d26
b727250
9083e84
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 |
---|---|---|
|
@@ -535,10 +535,11 @@ def test_get_indexer_pyarrow(self, as_td): | |
tm.assert_numpy_array_equal(result2, expected) | ||
|
||
def test_get_indexer_date_objs(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. instead of removing the test entirely, test the new behavior, with a comment about the history/change 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. (havent looked closely, but this likely applies to tests below) |
||
# GH#62158 date objects lose indexing special case | ||
rng = date_range("1/1/2000", periods=20) | ||
|
||
result = rng.get_indexer(rng.map(lambda x: x.date())) | ||
expected = rng.get_indexer(rng) | ||
|
||
expected = np.full(len(rng), -1, dtype=np.intp) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
def test_get_indexer(self): | ||
|
@@ -583,17 +584,23 @@ def test_get_indexer(self): | |
idx.get_indexer(idx[[0]], method="nearest", tolerance="foo") | ||
|
||
@pytest.mark.parametrize( | ||
"target", | ||
"target, expected", | ||
[ | ||
[date(2020, 1, 1), Timestamp("2020-01-02")], | ||
[Timestamp("2020-01-01"), date(2020, 1, 2)], | ||
( | ||
[date(2020, 1, 1), Timestamp("2020-01-02")], | ||
np.array([-1, 1], dtype=np.intp), | ||
), | ||
( | ||
[Timestamp("2020-01-01"), date(2020, 1, 2)], | ||
np.array([0, -1], dtype=np.intp), | ||
), | ||
], | ||
) | ||
def test_get_indexer_mixed_dtypes(self, target): | ||
# https://github.com/pandas-dev/pandas/issues/33741 | ||
def test_get_indexer_mixed_dtypes(self, target, expected): | ||
# GH#33741 regression test: mixed dtypes should not error | ||
# GH#62158 date objects lose indexing special case | ||
values = DatetimeIndex([Timestamp("2020-01-01"), Timestamp("2020-01-02")]) | ||
result = values.get_indexer(target) | ||
expected = np.array([0, 1], dtype=np.intp) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
@pytest.mark.parametrize( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,13 +275,24 @@ def test_categorical_coerces_numeric(all_parsers): | |
def test_categorical_coerces_datetime(all_parsers): | ||
parser = all_parsers | ||
dti = pd.DatetimeIndex(["2017-01-01", "2018-01-01", "2019-01-01"], freq=None) | ||
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. why is this removed? |
||
|
||
dtype = {"b": CategoricalDtype(dti)} | ||
|
||
data = "b\n2017-01-01\n2018-01-01\n2019-01-01" | ||
expected = DataFrame({"b": Categorical(dtype["b"].categories)}) | ||
|
||
result = parser.read_csv(StringIO(data), dtype=dtype) | ||
tm.assert_frame_equal(result, expected) | ||
if parser.engine == "pyarrow": | ||
msg = "Constructing a Categorical with a dtype and values containing" | ||
with tm.assert_produces_warning( | ||
Pandas4Warning, match=msg, check_stacklevel=False | ||
): | ||
result = parser.read_csv(StringIO(data), dtype=dtype) | ||
tm.assert_series_equal( | ||
result["b"].isna(), pd.Series([True, True, True], name="b") | ||
) | ||
else: | ||
result = parser.read_csv(StringIO(data), dtype=dtype) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_categorical_coerces_timestamp(all_parsers): | ||
|
@@ -291,8 +302,16 @@ def test_categorical_coerces_timestamp(all_parsers): | |
data = "b\n2014-01-01\n2014-01-01" | ||
expected = DataFrame({"b": Categorical([Timestamp("2014")] * 2)}) | ||
|
||
result = parser.read_csv(StringIO(data), dtype=dtype) | ||
tm.assert_frame_equal(result, expected) | ||
if parser.engine == "pyarrow": | ||
msg = "Constructing a Categorical with a dtype and values containing" | ||
with tm.assert_produces_warning( | ||
Pandas4Warning, match=msg, check_stacklevel=False | ||
): | ||
result = parser.read_csv(StringIO(data), dtype=dtype) | ||
tm.assert_series_equal(result["b"].isna(), pd.Series([True, True], name="b")) | ||
else: | ||
result = parser.read_csv(StringIO(data), dtype=dtype) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_categorical_coerces_timedelta(all_parsers): | ||
|
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.
this might be worth doing, but the motivating issue I opened was only about the check in indexes.base
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.
in my testing after removing the check in indexes.base, the example in the original issue still fails because of _infer_matches called under _validate_listlike
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.
OK, looking at the other places where _infer_matches is used, im OK with that change, but will need to make sure we have appropriate testing and whatsnew note for e.g. equals