Skip to content

type dataframe.transpose #1136

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

Merged
merged 5 commits into from
Mar 4, 2025
Merged

Conversation

MarcoGorelli
Copy link
Member

  • Closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added: Please use assert_type() to assert the type of any return value

Comment on lines 1601 to 1542
def transpose(self, *args, **kwargs) -> Series[S1]: ...
def transpose(self, axes: None = ...) -> Series[S1]: ...
Copy link
Member Author

Choose a reason for hiding this comment

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

The only argument that pandas actually lets us pass at runtime is axes=None

https://github.com/pandas-dev/pandas/blob/d831326e11971af61307e4fc940855556ef3cdb7/pandas/compat/numpy/function.py#L317-L320

For Series and Index, it can be passed positionally or by name

For DataFrame, it can only be passed positionally

Comment on lines 56 to 59
def transpose(self, *axes): ...
def transpose(self, *axes: Any) -> Self: ...
Copy link
Member Author

Choose a reason for hiding this comment

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

axes is totally ignored in SparseArray.transpose

@MarcoGorelli MarcoGorelli marked this pull request as ready for review March 2, 2025 11:48
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

I think we need to delete transpose() from everywhere except in pandas/core/frame.pyi because only DataFrame.transpose() is documented. And even for that method, the axes argument isn't documented, so we should leave it out of the pandas stubs.

@@ -53,7 +56,7 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin):
def sum(self, axis: int = ..., *args, **kwargs): ...
def cumsum(self, axis: int = ..., *args, **kwargs): ...
def mean(self, axis: int = ..., *args, **kwargs): ...
def transpose(self, *axes): ...
def transpose(self, *axes: Any) -> Self: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should delete this. SparseArray.transpose() is not documented. In fact, only the constructor is documented, so we should delete all the methods for SparseArray except __init__(). Can you do that here?

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

Need to remove the tests in test_series.py and test_indexes.py that you added for transpose there.

@MarcoGorelli MarcoGorelli changed the title type transpose type dataframe.transpose Mar 4, 2025
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

thanks @MarcoGorelli

@Dr-Irv Dr-Irv merged commit 8c569cf into pandas-dev:main Mar 4, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants