@@ -458,7 +458,7 @@ def _validate_dtype(cls, dtype) -> DtypeObj | None:
458
458
# Construction
459
459
460
460
@property
461
- def _constructor (self : NDFrameT ) -> type [ NDFrameT ]:
461
+ def _constructor (self : NDFrameT ) -> Callable [..., NDFrameT ]:
462
462
"""
463
463
Used when a manipulation result has the same dimensions as the
464
464
original.
@@ -793,17 +793,9 @@ def swapaxes(self: NDFrameT, axis1, axis2, copy=True) -> NDFrameT:
793
793
if copy :
794
794
new_values = new_values .copy ()
795
795
796
- # ignore needed because of NDFrame constructor is different than
797
- # DataFrame/Series constructors.
798
796
return self ._constructor (
799
- # error: Argument 1 to "NDFrame" has incompatible type "ndarray"; expected
800
- # "Union[ArrayManager, BlockManager]"
801
- # error: Argument 2 to "NDFrame" has incompatible type "*Generator[Index,
802
- # None, None]"; expected "bool" [arg-type]
803
- # error: Argument 2 to "NDFrame" has incompatible type "*Generator[Index,
804
- # None, None]"; expected "Optional[Mapping[Hashable, Any]]"
805
- new_values , # type: ignore[arg-type]
806
- * new_axes , # type: ignore[arg-type]
797
+ new_values ,
798
+ * new_axes ,
807
799
).__finalize__ (self , method = "swapaxes" )
808
800
809
801
@final
@@ -2100,11 +2092,7 @@ def __array_wrap__(
2100
2092
# ptp also requires the item_from_zerodim
2101
2093
return res
2102
2094
d = self ._construct_axes_dict (self ._AXIS_ORDERS , copy = False )
2103
- # error: Argument 1 to "NDFrame" has incompatible type "ndarray";
2104
- # expected "BlockManager"
2105
- return self ._constructor (res , ** d ).__finalize__ ( # type: ignore[arg-type]
2106
- self , method = "__array_wrap__"
2107
- )
2095
+ return self ._constructor (res , ** d ).__finalize__ (self , method = "__array_wrap__" )
2108
2096
2109
2097
@final
2110
2098
def __array_ufunc__ (
@@ -6612,8 +6600,10 @@ def replace(
6612
6600
6613
6601
if isinstance (to_replace , (tuple , list )):
6614
6602
if isinstance (self , ABCDataFrame ):
6603
+ from pandas import Series
6604
+
6615
6605
result = self .apply (
6616
- self . _constructor_sliced ._replace_single ,
6606
+ Series ._replace_single ,
6617
6607
args = (to_replace , method , inplace , limit ),
6618
6608
)
6619
6609
if inplace :
@@ -9137,11 +9127,7 @@ def _where(
9137
9127
9138
9128
# we are the same shape, so create an actual object for alignment
9139
9129
else :
9140
- # error: Argument 1 to "NDFrame" has incompatible type "ndarray";
9141
- # expected "BlockManager"
9142
- other = self ._constructor (
9143
- other , ** self ._construct_axes_dict () # type: ignore[arg-type]
9144
- )
9130
+ other = self ._constructor (other , ** self ._construct_axes_dict ())
9145
9131
9146
9132
if axis is None :
9147
9133
axis = 0
0 commit comments