Skip to content

TYP: Add type hint for DataFrame.T and certain array types #32532

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 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ def __setstate__(self, state):
setattr(self, k, v)

@property
def T(self):
def T(self) -> "Categorical":
"""
Return transposed numpy array.
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,14 +1296,14 @@ def mean(self, axis=0, *args, **kwargs):
nsparse = self.sp_index.ngaps
return (sp_sum + self.fill_value * nsparse) / (ct + nsparse)

def transpose(self, *axes):
def transpose(self, *axes) -> "SparseArray":
"""
Returns the SparseArray.
"""
return self

@property
def T(self):
def T(self) -> "SparseArray":
"""
Returns the SparseArray.
"""
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2443,7 +2443,9 @@ def transpose(self, *args, copy: bool = False) -> "DataFrame":

return result.__finalize__(self)

T = property(transpose)
@property
def T(self) -> "DataFrame":
return self.transpose()

# ----------------------------------------------------------------------
# Indexing Methods
Expand Down