-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 7 commits
198474d
6eba1c9
11b4f29
1b3cba1
d83cff9
4e66228
ac85aa3
2d25c7a
3e78985
7e600c7
05a788c
b136ce3
d433d7c
00199f6
01f01fd
8cfa045
4f8fccd
0f8a913
9d4d1df
a01a676
26f8ed3
3caf161
8d9e6d7
fbc31c8
c7e7cf5
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
""" test label based indexing with loc """ | ||
from datetime import timezone | ||
from io import StringIO | ||
import re | ||
|
||
|
@@ -1015,3 +1016,42 @@ def test_loc_slice_disallows_positional(): | |
with tm.assert_produces_warning(FutureWarning): | ||
# GH#31840 deprecated incorrect behavior | ||
df.loc[1:3, 1] = 2 | ||
|
||
|
||
def test_loc_setitem_df_datetime64tz_column_with_index(): | ||
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 a comment with the issue number |
||
pd.date_range("2020-01-01", "2020-01-06", 6, tz=timezone.utc), columns=["data"] | ||
) | ||
df2 = pd.DataFrame(index=df.index) | ||
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. use result = as its not really clear what you are comparing here |
||
df2.loc[df.index, "data"] = df["data"] | ||
tm.assert_numpy_array_equal(np.array(df.data), np.array(df2.data)) | ||
h-vishal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert df2.data.dtype == np.object | ||
|
||
|
||
def test_loc_setitem_df_datetime64tz_column_without_index(): | ||
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. you don't need to repeat things like this, instead we aleady have generic tests in : pandas/tests/extension//base/setitem.py 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. @h-vishal this is the key comment. Please do not repeat things like this. We already have fixtures for all of these. 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. @jreback I have pushed a commit with the requested changes. 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. it doesn't look like anything has changed. there should be NO tests here, rather in pandas/tests/extension/base/setitem |
||
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_series_equal(df.data, df2.data) | ||
|
||
|
||
def test_loc_setitem_series_datetime64tz_with_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=np.object, name="data") | ||
s2.loc[s1.index] = s1 | ||
tm.assert_numpy_array_equal(np.array(s1), np.array(s2)) | ||
assert s2.dtype == np.object | ||
|
||
|
||
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=np.object, name="data") | ||
s2.loc[:] = s1 | ||
tm.assert_numpy_array_equal(np.array(s1), np.array(s2)) | ||
assert s2.dtype == np.object |
Uh oh!
There was an error while loading. Please reload this page.