@@ -458,7 +458,7 @@ def _validate_dtype(cls, dtype) -> DtypeObj | None:
458458 # Construction
459459
460460 @property
461- def _constructor (self : NDFrameT ) -> type [ NDFrameT ]:
461+ def _constructor (self : NDFrameT ) -> Callable [..., NDFrameT ]:
462462 """
463463 Used when a manipulation result has the same dimensions as the
464464 original.
@@ -793,17 +793,9 @@ def swapaxes(self: NDFrameT, axis1, axis2, copy=True) -> NDFrameT:
793793 if copy :
794794 new_values = new_values .copy ()
795795
796- # ignore needed because of NDFrame constructor is different than
797- # DataFrame/Series constructors.
798796 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 ,
807799 ).__finalize__ (self , method = "swapaxes" )
808800
809801 @final
@@ -2100,11 +2092,7 @@ def __array_wrap__(
21002092 # ptp also requires the item_from_zerodim
21012093 return res
21022094 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__" )
21082096
21092097 @final
21102098 def __array_ufunc__ (
@@ -6612,8 +6600,10 @@ def replace(
66126600
66136601 if isinstance (to_replace , (tuple , list )):
66146602 if isinstance (self , ABCDataFrame ):
6603+ from pandas import Series
6604+
66156605 result = self .apply (
6616- self . _constructor_sliced ._replace_single ,
6606+ Series ._replace_single ,
66176607 args = (to_replace , method , inplace , limit ),
66186608 )
66196609 if inplace :
@@ -9137,11 +9127,7 @@ def _where(
91379127
91389128 # we are the same shape, so create an actual object for alignment
91399129 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 ())
91459131
91469132 if axis is None :
91479133 axis = 0
0 commit comments