@@ -444,7 +444,7 @@ def _validate_dtype(cls, dtype) -> DtypeObj | None:
444444 # Construction
445445
446446 @property
447- def _constructor (self : NDFrameT ) -> type [ NDFrameT ]:
447+ def _constructor (self : NDFrameT ) -> Callable [..., NDFrameT ]:
448448 """
449449 Used when a manipulation result has the same dimensions as the
450450 original.
@@ -779,17 +779,9 @@ def swapaxes(self: NDFrameT, axis1, axis2, copy=True) -> NDFrameT:
779779 if copy :
780780 new_values = new_values .copy ()
781781
782- # ignore needed because of NDFrame constructor is different than
783- # DataFrame/Series constructors.
784782 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 ,
793785 ).__finalize__ (self , method = "swapaxes" )
794786
795787 @final
@@ -2088,11 +2080,7 @@ def __array_wrap__(
20882080 # ptp also requires the item_from_zerodim
20892081 return res
20902082 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__" )
20962084
20972085 @final
20982086 def __array_ufunc__ (
@@ -5923,11 +5911,9 @@ def astype(
59235911 # GH 19920: retain column metadata after concat
59245912 result = concat (results , axis = 1 , copy = False )
59255913 # 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]
59315917 result .columns = self .columns
59325918 result = result .__finalize__ (self , method = "astype" )
59335919 # https://github.com/python/mypy/issues/8354
@@ -6613,8 +6599,10 @@ def replace(
66136599
66146600 if isinstance (to_replace , (tuple , list )):
66156601 if isinstance (self , ABCDataFrame ):
6602+ from pandas import Series
6603+
66166604 result = self .apply (
6617- self . _constructor_sliced ._replace_single ,
6605+ Series ._replace_single ,
66186606 args = (to_replace , method , inplace , limit ),
66196607 )
66206608 if inplace :
@@ -9139,11 +9127,7 @@ def _where(
91399127
91409128 # we are the same shape, so create an actual object for alignment
91419129 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 ())
91479131
91489132 if axis is None :
91499133 axis = 0
0 commit comments