Skip to content

Commit 817d57d

Browse files
authored
TYP: Add type hint for DataFrame.T and certain array types (#32532)
1 parent 362aef1 commit 817d57d

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

pandas/core/arrays/categorical.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ def __setstate__(self, state):
13171317
setattr(self, k, v)
13181318

13191319
@property
1320-
def T(self):
1320+
def T(self) -> "Categorical":
13211321
"""
13221322
Return transposed numpy array.
13231323
"""

pandas/core/arrays/sparse/array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1296,14 +1296,14 @@ def mean(self, axis=0, *args, **kwargs):
12961296
nsparse = self.sp_index.ngaps
12971297
return (sp_sum + self.fill_value * nsparse) / (ct + nsparse)
12981298

1299-
def transpose(self, *axes):
1299+
def transpose(self, *axes) -> "SparseArray":
13001300
"""
13011301
Returns the SparseArray.
13021302
"""
13031303
return self
13041304

13051305
@property
1306-
def T(self):
1306+
def T(self) -> "SparseArray":
13071307
"""
13081308
Returns the SparseArray.
13091309
"""

pandas/core/frame.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,9 @@ def transpose(self, *args, copy: bool = False) -> "DataFrame":
24452445

24462446
return result.__finalize__(self)
24472447

2448-
T = property(transpose)
2448+
@property
2449+
def T(self) -> "DataFrame":
2450+
return self.transpose()
24492451

24502452
# ----------------------------------------------------------------------
24512453
# Indexing Methods

0 commit comments

Comments
 (0)