Skip to content

Commit 1cd95d1

Browse files
committed
type transpose
1 parent 54b15c3 commit 1cd95d1

File tree

7 files changed

+28
-4
lines changed

7 files changed

+28
-4
lines changed

pandas-stubs/core/arrays/sparse/array.pyi

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from typing import Any
2+
13
import numpy as np
24
from pandas.core.arrays import (
35
ExtensionArray,
46
ExtensionOpsMixin,
57
)
8+
from typing_extensions import Self
69

710
class SparseArray(ExtensionArray, ExtensionOpsMixin):
811
def __init__(
@@ -53,7 +56,7 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin):
5356
def sum(self, axis: int = ..., *args, **kwargs): ...
5457
def cumsum(self, axis: int = ..., *args, **kwargs): ...
5558
def mean(self, axis: int = ..., *args, **kwargs): ...
56-
def transpose(self, *axes): ...
59+
def transpose(self, *axes: Any) -> Self: ...
5760
@property
5861
def T(self): ...
5962
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): ...

pandas-stubs/core/base.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class SelectionMixin(Generic[NDFrameT]):
4444

4545
class IndexOpsMixin(OpsMixin, Generic[S1]):
4646
__array_priority__: int = ...
47-
def transpose(self, *args, **kwargs) -> Self: ...
47+
def transpose(self, axes: None = ...) -> Self: ...
4848
@property
4949
def T(self) -> Self: ...
5050
@property

pandas-stubs/core/frame.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
655655
show_counts: bool | None = ...,
656656
) -> None: ...
657657
def memory_usage(self, index: _bool = ..., deep: _bool = ...) -> Series: ...
658-
def transpose(self, *args, copy: _bool = ...) -> Self: ...
658+
def transpose(self, axes: None = ..., /, copy: _bool = ...) -> Self: ...
659659
@property
660660
def T(self) -> Self: ...
661661
def __getattr__(self, name: str) -> Series: ...

pandas-stubs/core/series.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
15981598
bins: int | None = ...,
15991599
dropna: _bool = ...,
16001600
) -> Series[float]: ...
1601-
def transpose(self, *args, **kwargs) -> Series[S1]: ...
1601+
def transpose(self, axes: None = ...) -> Series[S1]: ...
16021602
@property
16031603
def T(self) -> Self: ...
16041604
# The rest of these were left over from the old

tests/test_frame.py

+7
Original file line numberDiff line numberDiff line change
@@ -3854,3 +3854,10 @@ def test_hashable_args() -> None:
38543854
# GH 906
38553855
@pd.api.extensions.register_dataframe_accessor("geo")
38563856
class GeoAccessor: ...
3857+
3858+
3859+
def test_transpose() -> None:
3860+
df = pd.DataFrame({"a": [1, 1, 2], "b": [4, 5, 6]})
3861+
check(assert_type(df.transpose(), pd.DataFrame), pd.DataFrame)
3862+
check(assert_type(df.transpose(None), pd.DataFrame), pd.DataFrame)
3863+
check(assert_type(df.transpose(copy=True), pd.DataFrame), pd.DataFrame)

tests/test_indexes.py

+7
Original file line numberDiff line numberDiff line change
@@ -1201,3 +1201,10 @@ def test_disallow_empty_index() -> None:
12011201
# From GH 826
12021202
if TYPE_CHECKING_INVALID_USAGE:
12031203
i0 = pd.Index() # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
1204+
1205+
1206+
def test_transpose() -> None:
1207+
idx: pd.Index[int] = pd.Index([1, 1, 2])
1208+
check(assert_type(idx.transpose(), "pd.Index[int]"), pd.Index, np.int64)
1209+
check(assert_type(idx.transpose(None), "pd.Index[int]"), pd.Index, np.int64)
1210+
check(assert_type(idx.transpose(axes=None), "pd.Index[int]"), pd.Index, np.int64)

tests/test_series.py

+7
Original file line numberDiff line numberDiff line change
@@ -3552,3 +3552,10 @@ def test_series_int_float() -> None:
35523552
check(
35533553
assert_type(pd.Series([1, 2.0, 3]), "pd.Series[float]"), pd.Series, np.float64
35543554
)
3555+
3556+
3557+
def test_transpose() -> None:
3558+
s: pd.Series[int] = pd.Series([1, 1, 2])
3559+
check(assert_type(s.transpose(), "pd.Series[int]"), pd.Series, np.int64)
3560+
check(assert_type(s.transpose(None), "pd.Series[int]"), pd.Series, np.int64)
3561+
check(assert_type(s.transpose(axes=None), "pd.Series[int]"), pd.Series, np.int64)

0 commit comments

Comments
 (0)