Skip to content

Commit 6189b5c

Browse files
committed
type transpose
1 parent 4b42588 commit 6189b5c

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
@@ -656,7 +656,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
656656
show_counts: bool | None = ...,
657657
) -> None: ...
658658
def memory_usage(self, index: _bool = ..., deep: _bool = ...) -> Series: ...
659-
def transpose(self, *args, copy: _bool = ...) -> Self: ...
659+
def transpose(self, axes: None = ..., /, copy: _bool = ...) -> Self: ...
660660
@property
661661
def T(self) -> Self: ...
662662
def __getattr__(self, name: str) -> Series: ...

pandas-stubs/core/series.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
15391539
bins: int | None = ...,
15401540
dropna: _bool = ...,
15411541
) -> Series[float]: ...
1542-
def transpose(self, *args, **kwargs) -> Series[S1]: ...
1542+
def transpose(self, axes: None = ...) -> Series[S1]: ...
15431543
@property
15441544
def T(self) -> Self: ...
15451545
# The rest of these were left over from the old

tests/test_frame.py

+7
Original file line numberDiff line numberDiff line change
@@ -4000,3 +4000,10 @@ def test_hashable_args() -> None:
40004000
# GH 906
40014001
@pd.api.extensions.register_dataframe_accessor("geo")
40024002
class GeoAccessor: ...
4003+
4004+
4005+
def test_transpose() -> None:
4006+
df = pd.DataFrame({"a": [1, 1, 2], "b": [4, 5, 6]})
4007+
check(assert_type(df.transpose(), pd.DataFrame), pd.DataFrame)
4008+
check(assert_type(df.transpose(None), pd.DataFrame), pd.DataFrame)
4009+
check(assert_type(df.transpose(copy=True), pd.DataFrame), pd.DataFrame)

tests/test_indexes.py

+7
Original file line numberDiff line numberDiff line change
@@ -1272,3 +1272,10 @@ def test_datetime_index_max_min_reductions() -> None:
12721272
check(assert_type(dtidx.argmin(), np.int64), np.int64)
12731273
check(assert_type(dtidx.max(), pd.Timestamp), pd.Timestamp)
12741274
check(assert_type(dtidx.min(), pd.Timestamp), pd.Timestamp)
1275+
1276+
1277+
def test_transpose() -> None:
1278+
idx: pd.Index[int] = pd.Index([1, 1, 2])
1279+
check(assert_type(idx.transpose(), "pd.Index[int]"), pd.Index, np.int64)
1280+
check(assert_type(idx.transpose(None), "pd.Index[int]"), pd.Index, np.int64)
1281+
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
@@ -3672,3 +3672,10 @@ def test_info() -> None:
36723672
check(assert_type(s.info(show_counts=True), None), type(None))
36733673
check(assert_type(s.info(show_counts=False), None), type(None))
36743674
check(assert_type(s.info(show_counts=None), None), type(None))
3675+
3676+
3677+
def test_transpose() -> None:
3678+
s: pd.Series[int] = pd.Series([1, 1, 2])
3679+
check(assert_type(s.transpose(), "pd.Series[int]"), pd.Series, np.int64)
3680+
check(assert_type(s.transpose(None), "pd.Series[int]"), pd.Series, np.int64)
3681+
check(assert_type(s.transpose(axes=None), "pd.Series[int]"), pd.Series, np.int64)

0 commit comments

Comments
 (0)