-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
TST: setitem preserving period[D] dtype #52704
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
TST: setitem preserving period[D] dtype #52704
Conversation
| expected = df.dtypes | ||
| df.iloc[:] = rng._na_value | ||
| result = df.dtypes | ||
| tm.assert_equal(result, expected) |
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.
Please construct the expected DataFrame and use tm.assert_frame_equal
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.
Please construct the expected DataFrame and use tm.assert_frame_equal
I'm a bit confused here, I thought that way but after executing this line df.iloc[:] = rng._na_value we get following o/p
# o/p of df.iloc[:] = rng._na_value
A
0 NaT
1 NaT
2 NaT
3 NaT
4 NaT
5 NaT
6 NaT
7 NaT
8 NaT
# And it's data type
# -> df.dtypes
A period[D]
dtype: objectand that was a result.
but for expected when I tried creating the same data frame and changing its type to period[D] it did not work.
expected = pd.DataFrame({"A": ['NaT', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT']})
expected.astype(obj.dtypes) # 1 did not work
expected.astype("period[D]") # 2 did not work
expected.dtypes
# o/p
A object
dtype: objectas per your suggestion, we can create a new data frame using period_range and compare using tm.assert_frame_equal here dtypes would be the same but the data is different so the test will fail.
I hope I'm able to describe the confusion clearly here.
Please let me know your thoughts on this.
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 [3]: pd.DataFrame({"A": ["NaT"]}, dtype="period[D]")
Out[3]:
A
0 NaT
In [4]: pd.DataFrame({"A": ["NaT"]}, dtype="period[D]").dtypes
Out[4]:
A period[D]
dtype: object
| assert expected["d"].dtype == arr.dtype | ||
| tm.assert_frame_equal(df, expected) | ||
|
|
||
| def test_setitem_periodd_dtype(self): |
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.
typo extra "d"
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.
typo extra "d"
Originally its period[D] but to name a function I thought this would be fine.
But I think there are ways we can rename
..._period_d_dtpye(self)..._period_dtype(self)
What do you think?
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.
_period_d_dtype is fine
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.
Okay! sounds good 👍
Thanks
|
Thanks @srkds |
|
Thanks @mroeschke and @jbrockmendel for review ❤😀 |
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.