-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
BUG: Fix issue with datetime[ns, tz] input in Block.setitem GH32395 #32479
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 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
198474d
BUG: Fix issue with datetime[ns, tz] input in Block.setitem GH32395
h-vishal 6eba1c9
Added tests for series, moved tests to test_loc.py
h-vishal 11b4f29
Add dtype to series object in tests to suppress warning
h-vishal 1b3cba1
Fix whatsnew
h-vishal d83cff9
Merge remote-tracking branch 'remotes/upstream/master' into issue-32395
h-vishal 4e66228
Merge remote-tracking branch 'remotes/upstream/master' into issue-32395
h-vishal ac85aa3
Merge remote-tracking branch 'remotes/upstream/master' into issue-32395
h-vishal 2d25c7a
Merge remote-tracking branch 'remotes/upstream/master' into issue-32395
h-vishal 3e78985
Move whatsnew to 1.1.0
h-vishal 7e600c7
Genralise fix for other extension array types
h-vishal 05a788c
Merge remote-tracking branch 'remotes/upstream/master' into issue-32395
h-vishal b136ce3
Add new whatsnew
h-vishal d433d7c
Fix doc
h-vishal 00199f6
Fix version number in whatsnew
h-vishal 01f01fd
Merge remote-tracking branch 'remotes/upstream/master' into issue-32395
h-vishal 8cfa045
TST: Fix precision test in tests.computation.test_eval.check_alignment()
h-vishal 4f8fccd
Revert "TST: Fix precision test in
h-vishal 0f8a913
CLN: Test style tests.indexing.test_loc
h-vishal 9d4d1df
Merge remote-tracking branch 'remotes/upstream/master' into issue-32395
h-vishal a01a676
Modify tests after review
h-vishal 26f8ed3
Merge remote-tracking branch 'remotes/upstream/master' into issue-32395
h-vishal 3caf161
Merge remote-tracking branch 'upstream/master' into issue-32395
simonjayhawkins 8d9e6d7
Merge remote-tracking branch 'upstream/master' into issue-32395
simonjayhawkins fbc31c8
nits
simonjayhawkins c7e7cf5
update tests
simonjayhawkins 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
Modify tests after review
- Loading branch information
commit a01a676918835404ba07d89e7b37c2b56a5a0258
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ Version 1.0 | |
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
v1.0.4 | ||
v1.0.3 | ||
v1.0.2 | ||
v1.0.1 | ||
|
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 |
---|---|---|
|
@@ -26,4 +26,4 @@ Bug fixes | |
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
.. contributors:: v1.0.2..v1.0.3 | ||
.. contributors:: v1.0.2..v1.0.3|HEAD |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -1110,19 +1110,21 @@ def test_loc_with_period_index_indexer(): | |
|
||
|
||
def test_loc_setitem_df_datetime64tz_full_column_with_index(): | ||
df = pd.DataFrame( | ||
# GH#32395 ea assignments with an index raise TypeError | ||
expected = pd.DataFrame( | ||
pd.date_range("2020-01-01", "2020-01-06", 6, tz=timezone.utc), columns=["data"] | ||
) | ||
df2 = pd.DataFrame(index=df.index) | ||
df2.loc[df.index, "data"] = df["data"] | ||
tm.assert_frame_equal(df, df2) | ||
result = pd.DataFrame(index=expected.index) | ||
result.loc[expected.index, "data"] = expected["data"] | ||
tm.assert_frame_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_df_datetime64tz_slice(): | ||
# GH#32395 ea assignments with an index raise TypeError | ||
df = pd.DataFrame( | ||
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. add the issue number as a comment |
||
pd.date_range("2020-01-01", "2020-01-06", 6, tz=timezone.utc), columns=["data"] | ||
) | ||
df2 = pd.DataFrame(index=df.index) | ||
result = pd.DataFrame(index=df.index) | ||
expected = pd.DataFrame( | ||
[ | ||
pd.Timestamp("2020-01-01", tz=timezone.utc), | ||
|
@@ -1135,109 +1137,103 @@ def test_loc_setitem_df_datetime64tz_slice(): | |
columns=["data"], | ||
dtype="object", | ||
) | ||
df2.loc[df.index[:3], "data"] = df["data"][:3] | ||
tm.assert_frame_equal(df2, expected) | ||
|
||
|
||
def test_loc_setitem_df_datetime64tz_column_without_index(): | ||
df = pd.DataFrame( | ||
pd.date_range("2020-01-01", "2020-01-06", 6, tz=timezone.utc), columns=["data"] | ||
) | ||
df2 = pd.DataFrame(index=df.index) | ||
df2.loc[:, "data"] = df["data"] | ||
tm.assert_frame_equal(df, df2) | ||
result.loc[df.index[:3], "data"] = df["data"][:3] | ||
tm.assert_frame_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_series_datetime64tz_full_with_index(): | ||
s1 = pd.Series( | ||
# GH#32395 ea assignments with an index raise TypeError | ||
expected = pd.Series( | ||
pd.date_range("2020-01-01", "2020-01-06", 6, tz=timezone.utc), name="data" | ||
) | ||
s2 = pd.Series(index=s1.index, dtype="object", name="data") | ||
s2.loc[s1.index] = s1 | ||
tm.assert_series_equal(s1, s2) | ||
result = pd.Series(index=expected.index, dtype="object", name="data") | ||
result.loc[expected.index] = expected | ||
tm.assert_series_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_series_datetime64tz_slice(): | ||
# GH#32395 ea assignments with an index raise TypeError | ||
dates = pd.date_range("2020-01-01", "2020-01-06", 6, tz=timezone.utc) | ||
s1 = pd.Series(dates, name="data") | ||
s2 = pd.Series(index=s1.index, dtype="object", name="data") | ||
result = pd.Series(index=s1.index, dtype="object", name="data") | ||
expected = pd.Series(dates, name="data", dtype="object") | ||
expected[-3:] = pd.NaT | ||
s2.loc[s1.index[:3]] = s1[:3] | ||
tm.assert_series_equal(expected, s2) | ||
|
||
|
||
def test_loc_setitem_series_datetime64tz_without_index(): | ||
s1 = pd.Series( | ||
pd.date_range("2020-01-01", "2020-01-06", 6, tz=timezone.utc), name="data" | ||
) | ||
s2 = pd.Series(index=s1.index, dtype="object", name="data") | ||
s2.loc[:] = s1 | ||
tm.assert_series_equal(s1, s2) | ||
result.loc[s1.index[:3]] = s1[:3] | ||
tm.assert_series_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_series_timedelta64_full_with_index(): | ||
s1 = pd.Series(pd.timedelta_range(start="1 day", periods=4), name="data") | ||
s2 = pd.Series(index=s1.index, dtype="object", name="data") | ||
s2.loc[s1.index] = s1 | ||
tm.assert_series_equal(s1, s2) | ||
# GH#32395 ea assignments with an index raise TypeError | ||
expected = pd.Series(pd.timedelta_range(start="1 day", periods=4), name="data") | ||
result = pd.Series(index=expected.index, dtype="object", name="data") | ||
result.loc[expected.index] = expected | ||
tm.assert_series_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_df_period_full_column_with_index(): | ||
df = pd.DataFrame(pd.period_range(start="2020Q1", periods=5), columns=["data"]) | ||
df2 = pd.DataFrame(index=df.index) | ||
df2.loc[df.index, "data"] = df["data"] | ||
tm.assert_frame_equal(df, df2) | ||
# GH#32395 ea assignments with an index raise TypeError | ||
expected = pd.DataFrame( | ||
pd.period_range(start="2020Q1", periods=5), columns=["data"] | ||
) | ||
result = pd.DataFrame(index=expected.index) | ||
result.loc[expected.index, "data"] = expected["data"] | ||
tm.assert_frame_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_series_interval_full_with_index(): | ||
s1 = pd.Series(pd.interval_range(start=0, end=5), name="data") | ||
s2 = pd.Series(index=s1.index, dtype="object", name="data") | ||
s2.loc[s1.index] = s1 | ||
tm.assert_series_equal(s1, s2) | ||
# GH#32395 ea assignments with an index raise TypeError | ||
expected = pd.Series(pd.interval_range(start=0, end=5), name="data") | ||
result = pd.Series(index=expected.index, dtype="object", name="data") | ||
result.loc[expected.index] = expected | ||
tm.assert_series_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_df_sparse_full_column_with_index(): | ||
df = pd.DataFrame(np.random.randn(100), columns=["data"]) | ||
df.iloc[5:95] = np.nan | ||
df = df.astype(pd.SparseDtype("int", np.nan)) | ||
df2 = pd.DataFrame(index=df.index) | ||
df2.loc[df.index, "data"] = df["data"] | ||
tm.assert_frame_equal(df, df2) | ||
# GH#32395 ea assignments with an index raise TypeError | ||
expected = pd.DataFrame(np.random.randn(100), columns=["data"]) | ||
expected.iloc[5:95] = np.nan | ||
expected = expected.astype(pd.SparseDtype("int", np.nan)) | ||
result = pd.DataFrame(index=expected.index) | ||
result.loc[expected.index, "data"] = expected["data"] | ||
tm.assert_frame_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_series_categorical_full_with_index(): | ||
s1 = pd.Series(pd.Categorical([1] * 10 + [2] * 5 + [3] * 10), name="data") | ||
s2 = pd.Series(index=s1.index, dtype="object", name="data") | ||
s2.loc[s1.index] = s1 | ||
tm.assert_series_equal(s1, s2) | ||
# GH#32395 ea assignments with an index raise TypeError | ||
expected = pd.Series(pd.Categorical([1] * 10 + [2] * 5 + [3] * 10), name="data") | ||
result = pd.Series(index=expected.index, dtype="object", name="data") | ||
result.loc[expected.index] = expected | ||
tm.assert_series_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_series_categorical_slice(): | ||
# GH#32395 ea assignments with an index raise TypeError | ||
s1 = pd.Series(pd.Categorical([1] * 10 + [2] * 5 + [3] * 10), name="data") | ||
s2 = pd.Series(index=s1.index, dtype="object", name="data") | ||
result = pd.Series(index=s1.index, dtype="object", name="data") | ||
expected = pd.Series( | ||
pd.Categorical([1] * 10 + [2] * 5 + [np.nan] * 10), name="data", dtype=object | ||
) | ||
s2.loc[s1.index[:15]] = s1[:15] | ||
tm.assert_series_equal(expected, s2) | ||
result.loc[s1.index[:15]] = s1[:15] | ||
tm.assert_series_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_df_interval_slice(): | ||
# GH#32395 ea assignments with an index raise TypeError | ||
intervals = pd.interval_range(start=0, end=5) | ||
df = pd.DataFrame(intervals, columns=["data"]) | ||
df2 = pd.DataFrame(index=df.index) | ||
result = pd.DataFrame(index=df.index) | ||
expected = pd.DataFrame(intervals, columns=["data"], dtype="object") | ||
expected.data[-2:] = np.nan | ||
df2.loc[df.index[:3], "data"] = df["data"][:3] | ||
tm.assert_frame_equal(df2, expected) | ||
result.loc[df.index[:3], "data"] = df["data"][:3] | ||
tm.assert_frame_equal(expected, result) | ||
|
||
|
||
def test_loc_setitem_series_period_slice(): | ||
# GH#32395 ea assignments with an index raise TypeError | ||
periods = pd.period_range(start="2020Q1", periods=5) | ||
s1 = pd.Series(periods, name="data") | ||
s2 = pd.Series(index=s1.index, dtype="object", name="data") | ||
result = pd.Series(index=s1.index, dtype="object", name="data") | ||
expected = pd.Series(periods, name="data", dtype=object,) | ||
expected[-2:] = np.nan | ||
s2.loc[s1.index[:3]] = s1[:3] | ||
tm.assert_series_equal(expected, s2) | ||
result.loc[s1.index[:3]] = s1[:3] | ||
tm.assert_series_equal(expected, result) |
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.
all of this need to move to pandas/tests/extension/setitem
BUT you need to use the fixtures, so you are like writing ONE test.