Skip to content

BUG: transpose casts mixed dtypes to object #43340

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 13 commits into from

Conversation

debnathshoham
Copy link
Member

@debnathshoham
Copy link
Member Author

All the failures are from the below two, not sure why .These are passing in some cases (also in my local).
Would be really helpful if someone can point me to the correct direction.

FAILED pandas/tests/frame/methods/test_transpose.py::TestTranspose::test_transpose_tzaware_2col_mixed_tz
FAILED pandas/tests/frame/methods/test_transpose.py::TestTranspose::test_transpose_object_to_tzaware_mixed_tz

@mzeitlin11
Copy link
Member

All the failures are from the below two, not sure why .These are passing in some cases (also in my local).
Would be really helpful if someone can point me to the correct direction.

FAILED pandas/tests/frame/methods/test_transpose.py::TestTranspose::test_transpose_tzaware_2col_mixed_tz
FAILED pandas/tests/frame/methods/test_transpose.py::TestTranspose::test_transpose_object_to_tzaware_mixed_tz

Based on a quick look, initial guess might be different numpy versions. Maybe try using the same numpy version as one of the failing builds (or just see if you can reproduce with an matching requirements file, which you can find at pandas/ci/deps)

@mzeitlin11 mzeitlin11 added the Dtype Conversions Unexpected or buggy dtype conversions label Sep 2, 2021
@jbrockmendel
Copy link
Member

test_transpose_tzaware_2col_mixed_tz

Best guess is something weird is going on with find_common_type between dt64tz[US/Eastern] and dt64tz[US/Pacific]. I think find_common_type should return object, but in some places we pretend that the common type is dt64tz[UTC]

@jreback
Copy link
Contributor

jreback commented Oct 3, 2021

ok if you can merge master will look again

@@ -57,6 +58,7 @@ def test_transpose_object_to_tzaware_mixed_tz(self):
df2 = DataFrame([dti, dti2])
assert (df2.dtypes == object).all()
res2 = df2.T
print("\n", res2.dtypes, [dti.dtype, dti2.dtype])
Copy link
Contributor

Choose a reason for hiding this comment

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

remove prints

Copy link
Member Author

Choose a reason for hiding this comment

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

removed the prints
these are the only two tests failing (but not on my local, was trying to figure why)

@@ -501,6 +501,7 @@ Reshaping
- Improved error message when creating a :class:`DataFrame` column from a multi-dimensional :class:`numpy.ndarray` (:issue:`42463`)
- :func:`concat` creating :class:`MultiIndex` with duplicate level entries when concatenating a :class:`DataFrame` with duplicates in :class:`Index` and multiple keys (:issue:`42651`)
- Bug in :meth:`pandas.cut` on :class:`Series` with duplicate indices (:issue:`42185`) and non-exact :meth:`pandas.CategoricalIndex` (:issue:`42425`)
- Bug in :meth:`DataFrame.transpose`, where mixed dtypes were cast to ``object`` (:issue:`43337`)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is saying the opposite of what you are doing. make this more clear to a reader

new_arr = new_arr.copy()
result = self._constructor(new_arr, index=self.columns, columns=self.index)
common_dtype = find_common_type(dtypes) if len(dtypes) > 0 else None
result = self._constructor(
Copy link
Contributor

Choose a reason for hiding this comment

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

pass copy to the constructor (and are you testing this)?

@@ -103,3 +103,10 @@ def test_transpose_get_view_dt64tzget_view(self):

rtrip = result._mgr.blocks[0].values
assert np.shares_memory(arr._data, rtrip._data)

def test_transpose_mixed_dtypes(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

test the copy keyword. test an example which does keep object (e.g. (1, 1.5) and ( 'a', 1)) for (a, b) and test with simple dtypes as well (e.g. int64)

@jreback
Copy link
Contributor

jreback commented Oct 4, 2021

this very likley changes a number of tests you will have to edit those

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2021

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Nov 4, 2021
@jreback
Copy link
Contributor

jreback commented Nov 28, 2021

status of this?

@debnathshoham
Copy link
Member Author

sorry, was not able to give time into this..
will take a look again, sorry for the delay

@mroeschke
Copy link
Member

Thanks @debnathshoham but appears this PR has gone stale. When you have the time feel free to merge master and we can reopen. Closing for now.

@mroeschke mroeschke closed this Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: transpose unnecessarily returning object
5 participants