@@ -444,7 +444,7 @@ def _validate_dtype(cls, dtype) -> DtypeObj | None:
444
444
# Construction
445
445
446
446
@property
447
- def _constructor (self : NDFrameT ) -> type [ NDFrameT ]:
447
+ def _constructor (self : NDFrameT ) -> Callable [..., NDFrameT ]:
448
448
"""
449
449
Used when a manipulation result has the same dimensions as the
450
450
original.
@@ -779,17 +779,9 @@ def swapaxes(self: NDFrameT, axis1, axis2, copy=True) -> NDFrameT:
779
779
if copy :
780
780
new_values = new_values .copy ()
781
781
782
- # ignore needed because of NDFrame constructor is different than
783
- # DataFrame/Series constructors.
784
782
return self ._constructor (
785
- # error: Argument 1 to "NDFrame" has incompatible type "ndarray"; expected
786
- # "Union[ArrayManager, BlockManager]"
787
- # error: Argument 2 to "NDFrame" has incompatible type "*Generator[Index,
788
- # None, None]"; expected "bool" [arg-type]
789
- # error: Argument 2 to "NDFrame" has incompatible type "*Generator[Index,
790
- # None, None]"; expected "Optional[Mapping[Hashable, Any]]"
791
- new_values , # type: ignore[arg-type]
792
- * new_axes , # type: ignore[arg-type]
783
+ new_values ,
784
+ * new_axes ,
793
785
).__finalize__ (self , method = "swapaxes" )
794
786
795
787
@final
@@ -2088,11 +2080,7 @@ def __array_wrap__(
2088
2080
# ptp also requires the item_from_zerodim
2089
2081
return res
2090
2082
d = self ._construct_axes_dict (self ._AXIS_ORDERS , copy = False )
2091
- # error: Argument 1 to "NDFrame" has incompatible type "ndarray";
2092
- # expected "BlockManager"
2093
- return self ._constructor (res , ** d ).__finalize__ ( # type: ignore[arg-type]
2094
- self , method = "__array_wrap__"
2095
- )
2083
+ return self ._constructor (res , ** d ).__finalize__ (self , method = "__array_wrap__" )
2096
2084
2097
2085
@final
2098
2086
def __array_ufunc__ (
@@ -5923,11 +5911,9 @@ def astype(
5923
5911
# GH 19920: retain column metadata after concat
5924
5912
result = concat (results , axis = 1 , copy = False )
5925
5913
# GH#40810 retain subclass
5926
- # Incompatible types in assignment (expression has type "NDFrameT",
5927
- # variable has type "DataFrame")
5928
- # Argument 1 to "NDFrame" has incompatible type "DataFrame"; expected
5929
- # "Union[ArrayManager, SingleArrayManager, BlockManager, SingleBlockManager]"
5930
- result = self ._constructor (result ) # type: ignore[arg-type,assignment]
5914
+ # error: Incompatible types in assignment
5915
+ # (expression has type "NDFrameT", variable has type "DataFrame")
5916
+ result = self ._constructor (result ) # type: ignore[assignment]
5931
5917
result .columns = self .columns
5932
5918
result = result .__finalize__ (self , method = "astype" )
5933
5919
# https://github.com/python/mypy/issues/8354
@@ -6613,8 +6599,10 @@ def replace(
6613
6599
6614
6600
if isinstance (to_replace , (tuple , list )):
6615
6601
if isinstance (self , ABCDataFrame ):
6602
+ from pandas import Series
6603
+
6616
6604
result = self .apply (
6617
- self . _constructor_sliced ._replace_single ,
6605
+ Series ._replace_single ,
6618
6606
args = (to_replace , method , inplace , limit ),
6619
6607
)
6620
6608
if inplace :
@@ -9139,11 +9127,7 @@ def _where(
9139
9127
9140
9128
# we are the same shape, so create an actual object for alignment
9141
9129
else :
9142
- # error: Argument 1 to "NDFrame" has incompatible type "ndarray";
9143
- # expected "BlockManager"
9144
- other = self ._constructor (
9145
- other , ** self ._construct_axes_dict () # type: ignore[arg-type]
9146
- )
9130
+ other = self ._constructor (other , ** self ._construct_axes_dict ())
9147
9131
9148
9132
if axis is None :
9149
9133
axis = 0
0 commit comments