Skip to content

Commit eeb0417

Browse files
committed
TYP: Add type hint for DataFrame.T and certain array types
1 parent 684a291 commit eeb0417

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

doc/source/whatsnew/v1.1.0.rst

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

356358
.. ---------------------------------------------------------------------------
357359

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

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

24442444
return result.__finalize__(self)
24452445

2446-
T = property(transpose)
2446+
T: "DataFrame" = property(transpose)
24472447

24482448
# ----------------------------------------------------------------------
24492449
# Indexing Methods

0 commit comments

Comments
 (0)