-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix+test dataframe tranpose with datetimeTZ #23730
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
Hello @jbrockmendel! Thanks for submitting the PR.
|
@@ -939,3 +939,34 @@ def test_unstack_fill_frame_object(): | |||
index=list('xyz') | |||
) | |||
assert_frame_equal(result, expected) | |||
|
|||
|
|||
def test_transpose_dt64tz(): |
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.
Could you also test transposing a mixed dtype dataframe if we aren't already (e.g. datetimetz and int)?
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.
Will do. Only real difference is that it doesn't round-trip (though I think that behavior is correct)
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.
Yeah that makes sense. Just good to ensure that there's no aggressive coercion of other data dtypes in the DataFrame once transposed i.e. the columns in df.T
end up as object.
Codecov Report
@@ Coverage Diff @@
## master #23730 +/- ##
=========================================
Coverage ? 92.29%
=========================================
Files ? 161
Lines ? 51478
Branches ? 0
=========================================
Hits ? 47511
Misses ? 3967
Partials ? 0
Continue to review full report at Codecov.
|
pandas/core/generic.py
Outdated
utc_values = utc_values.copy() | ||
result = self._constructor(utc_values, **new_axes) | ||
if self.ndim > 2: | ||
# We're assuming DataFrame from here on |
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.
not sure why you should do this here at all. Move this to internals and just create new blocks, rather than hacking it.
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.
The point is that it is going to be a hack regardless unless we allow 2D EAs.
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.
not going to happen any time soon if ever
as i said this is way too hacky and needs to be pushed to internals
Updated to be a little prettier, but still fundamentally a kludge. @TomAugspurger @jorisvandenbossche thoughts on this? I maintain the non-kludge way to fix this is to allow 2D DatetimeArray. Also, will need its own issue, but adding to the "let's not layer on more kludges" pile:
|
@jbrockmendel I would rather you set this while transpose bizness aside. This needs to be pushed into internals, and does not need EA 2-D support to make this work. This kludge won't be accepted in its current form. Much rather get datetime EA fnished. This is not neceessary for that. |
Will look closely later, but I think the transpose stuff will be handled automatically by internals when DatetimeArray is an extension array. |
Travis fail is the test_rank segfault. An argument against 2D DatetimeArray: When other things clear up I'll take a look at pushing this into internals. This bug is high on my list of pet peeves at the moment, so I'm not likely to let it go. |
@jbrockmendel I would put this aside. This is just a hack and not worth the time / effort right now. Lots more fish to fry. This 'bug' has existed for quite a long time, and to be honest this is just a not-that interesting edge case. |
Closing as not actionable. |
Reminder of the bug here:
The implementation is an unholy mess. It can be made a little bit prettier, but to actually get a nice implementation we need to allow 2D EAs.