Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

parthi-siva
Copy link
Contributor

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.

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Testing pandas testing functions or related to the test suite labels Mar 18, 2022
@jreback jreback added this to the 1.5 milestone Mar 18, 2022
expected = DataFrame(
{"A": to_datetime(["2021", "2022"]), "B": ["2021", "2022"]}
)
tm.assert_frame_equal(df, expected, check_dtype=False)
Copy link
Contributor

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?

Copy link
Contributor Author

@parthi-siva parthi-siva Mar 19, 2022

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
>>> 

Copy link
Contributor

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

Copy link
Contributor Author

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

expected = DataFrame(
{"A": to_datetime(["2022-01-01", "2022-01-02"]), "B": ["2021", "2022"]}
)
tm.assert_frame_equal(df, expected, check_dtype=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@pep8speaks
Copy link

pep8speaks commented Mar 22, 2022

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

@parthi-siva parthi-siva force-pushed the TST_for_issue_#20511 branch from 1eb2894 to b33eb02 Compare March 22, 2022 08:08
@parthi-siva parthi-siva changed the title TST: Additional to iloc setitem TST: Additional tests to iloc setitem Mar 22, 2022
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.
@parthi-siva parthi-siva force-pushed the TST_for_issue_#20511 branch from 9cd71f1 to f449fd4 Compare March 24, 2022 01:33
@parthi-siva parthi-siva requested a review from jreback April 5, 2022 06:25
Copy link
Contributor Author

@parthi-siva parthi-siva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed as requested

@parthi-siva parthi-siva deleted the TST_for_issue_#20511 branch May 10, 2022 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assign back converted multiple columns to datetime failed
3 participants