-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: Additional tests to iloc setitem #46419
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
Conversation
pandas/tests/indexing/test_iloc.py
Outdated
expected = DataFrame( | ||
{"A": to_datetime(["2021", "2022"]), "B": ["2021", "2022"]} | ||
) | ||
tm.assert_frame_equal(df, expected, check_dtype=False) |
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.
why is check_dtype=False?
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.
Because the datatype remains as object after assign back. Not converted to datetime
>>> df = DataFrame({"A": ["2022-01-01", "2022-01-02"], "B": ["2021", "2022"]})
>>>
>>>
>>> df.iloc[:, [0]] = DataFrame({"A": to_datetime(["2021", "2022"])})
>>>
>>>
>>> df.dtypes
A object
B object
dtype: object
>>>
>>> df
A B
0 2021-01-01 00:00:00 2021
1 2022-01-01 00:00:00 2022
>>>
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.
then pls construct the exact expected series. this may actually be a bug
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.
After the assignment if we check the dtypes it shows as object
In [89]: df = DataFrame({"A": ["2022-01-01", "2022-01-02"], "B": ["2021", "2022"]})
In [90]: df.iloc[:, [0]] = df.iloc[:, [0]].apply(to_datetime)
In [91]: df.dtypes
Out[91]:
A object
B object
dtype: object
But if we use iat to take a look at one of the single value which is converted it show as Timestamp
In [92]: df.iat[0,0]
Out[92]: Timestamp('2022-01-01 00:00:00')
So constructed the exact expected frame using Timestamp and dtype as object
pandas/tests/indexing/test_iloc.py
Outdated
expected = DataFrame( | ||
{"A": to_datetime(["2022-01-01", "2022-01-02"]), "B": ["2021", "2022"]} | ||
) | ||
tm.assert_frame_equal(df, expected, check_dtype=False) |
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.
same
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.
same as above
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.
changed
Hello @parthi-siva! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2022-04-28 15:06:16 UTC |
1eb2894
to
b33eb02
Compare
This tests make sure when converting multiple columns to datetimes and when assiging back it remains as datetime not as unix date as mentioned in GH pandas-dev#20511.
9cd71f1
to
f449fd4
Compare
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.
changed as requested
This tests make sure when converting multiple columns to datetimes
and when assiging back it remains as datetime not as unix date
as mentioned in GH #20511.
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.