Skip to content

Commit 0687715

Browse files
committed
TYP: Add type hint for DataFrame.T and certain array types
1 parent f33120c commit 0687715

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

doc/source/whatsnew/v1.1.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ Other
353353
instead of ``TypeError: Can only append a Series if ignore_index=True or if the Series has a name`` (:issue:`30871`)
354354
- Set operations on an object-dtype :class:`Index` now always return object-dtype results (:issue:`31401`)
355355
- Bug in :meth:`AbstractHolidayCalendar.holidays` when no rules were defined (:issue:`31415`)
356+
- :meth:`DataFrame.T` now has type annotations in line with :meth:`DataFrame.transpose`. Annotations also extended to :class:`Categorical`
357+
and :class:`SparseArray` (:issue:`32532`)
356358

357359
.. ---------------------------------------------------------------------------
358360

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
@@ -2443,7 +2443,9 @@ def transpose(self, *args, copy: bool = False) -> "DataFrame":
24432443

24442444
return result.__finalize__(self)
24452445

2446-
T = property(transpose)
2446+
@property
2447+
def T(self) -> "DataFrame":
2448+
return self.transpose()
24472449

24482450
# ----------------------------------------------------------------------
24492451
# Indexing Methods

0 commit comments

Comments
 (0)