-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: transpose inferring dtype for dt in object column #51565
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 1 commit
9021944
0cf4e4c
3e8dc57
e5af65c
9926631
1522f8f
e2edec6
491200a
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 |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
DataFrame, | ||
DatetimeIndex, | ||
IntervalIndex, | ||
Series, | ||
Timestamp, | ||
date_range, | ||
timedelta_range, | ||
) | ||
|
@@ -63,7 +65,7 @@ def test_transpose_tzaware_2col_mixed_tz(self): | |
df4 = DataFrame({"A": dti, "B": dti2}) | ||
assert (df4.dtypes == [dti.dtype, dti2.dtype]).all() | ||
assert (df4.T.dtypes == object).all() | ||
tm.assert_frame_equal(df4.T.T, df4) | ||
tm.assert_frame_equal(df4.T.T, df4, check_dtype=False) | ||
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. can you cast the expected here to keep the test strict 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. done |
||
|
||
@pytest.mark.parametrize("tz", [None, "America/New_York"]) | ||
def test_transpose_preserves_dtindex_equality_with_dst(self, tz): | ||
|
@@ -83,7 +85,7 @@ def test_transpose_object_to_tzaware_mixed_tz(self): | |
df2 = DataFrame([dti, dti2]) | ||
assert (df2.dtypes == object).all() | ||
res2 = df2.T | ||
assert (res2.dtypes == [dti.dtype, dti2.dtype]).all() | ||
assert (res2.dtypes == object).all() | ||
|
||
def test_transpose_uint64(self, uint64_frame): | ||
result = uint64_frame.T | ||
|
@@ -128,3 +130,42 @@ def test_transpose_get_view_dt64tzget_view(self): | |
|
||
rtrip = result._mgr.blocks[0].values | ||
assert np.shares_memory(arr._ndarray, rtrip._ndarray) | ||
|
||
def test_transpose_not_inferring_dt(self): | ||
# GH#51546 | ||
df = DataFrame( | ||
{ | ||
"a": [Timestamp("2019-12-31"), Timestamp("2019-12-31")], | ||
}, | ||
dtype=object, | ||
) | ||
result = df.T | ||
expected = DataFrame( | ||
[[Timestamp("2019-12-31"), Timestamp("2019-12-31")]], | ||
columns=[0, 1], | ||
index=["a"], | ||
dtype=object, | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_transpose_not_inferring_dt_mixed_blocks(self): | ||
# GH#51546 | ||
df = DataFrame( | ||
{ | ||
"a": Series( | ||
[Timestamp("2019-12-31"), Timestamp("2019-12-31")], dtype=object | ||
), | ||
"b": [Timestamp("2019-12-31"), Timestamp("2019-12-31")], | ||
} | ||
) | ||
result = df.T | ||
expected = DataFrame( | ||
[ | ||
[Timestamp("2019-12-31"), Timestamp("2019-12-31")], | ||
[Timestamp("2019-12-31"), Timestamp("2019-12-31")], | ||
], | ||
columns=[0, 1], | ||
index=["a", "b"], | ||
dtype=object, | ||
) | ||
tm.assert_frame_equal(result, expected) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -464,7 +464,7 @@ def test_groupby_quantile_dt64tz_period(): | |
|
||
# Check that we match the group-by-group result | ||
exp = {i: df.iloc[i::5].quantile(0.5) for i in range(5)} | ||
expected = DataFrame(exp).T | ||
expected = DataFrame([x.tolist() for x in exp.values()], index=exp.keys()) | ||
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. could do .infer_objects()? 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. Good idea |
||
expected.index = expected.index.astype(np.int_) | ||
|
||
tm.assert_frame_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.
do we need to pass copy=False here (possibly just to be future-safe)?
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.
Yep, I’ll add it in the copy=True pr.
actually, it probably makes sense to go through all usages of constructor and pass copy=False for arrays. Will take a look how many there are