@@ -840,7 +840,7 @@ def view(self, dtype: Dtype | None = None) -> Series:
840840 # self.array instead of self._values so we piggyback on PandasArray
841841 # implementation
842842 res_values = self .array .view (dtype )
843- res_ser = self ._constructor (res_values , index = self .index )
843+ res_ser = self ._constructor (res_values , index = self .index , copy = False )
844844 if isinstance (res_ser ._mgr , SingleBlockManager ) and using_copy_on_write ():
845845 blk = res_ser ._mgr ._block
846846 blk .refs = cast ("BlockValuesRefs" , self ._references )
@@ -1073,7 +1073,7 @@ def _get_values_tuple(self, key: tuple):
10731073
10741074 # If key is contained, would have returned by now
10751075 indexer , new_index = self .index .get_loc_level (key )
1076- new_ser = self ._constructor (self ._values [indexer ], index = new_index )
1076+ new_ser = self ._constructor (self ._values [indexer ], index = new_index , copy = False )
10771077 if using_copy_on_write () and isinstance (indexer , slice ):
10781078 new_ser ._mgr .add_references (self ._mgr ) # type: ignore[arg-type]
10791079 return new_ser .__finalize__ (self )
@@ -1113,7 +1113,9 @@ def _get_value(self, label, takeable: bool = False):
11131113
11141114 new_index = mi [loc ]
11151115 new_index = maybe_droplevels (new_index , label )
1116- new_ser = self ._constructor (new_values , index = new_index , name = self .name )
1116+ new_ser = self ._constructor (
1117+ new_values , index = new_index , name = self .name , copy = False
1118+ )
11171119 if using_copy_on_write () and isinstance (loc , slice ):
11181120 new_ser ._mgr .add_references (self ._mgr ) # type: ignore[arg-type]
11191121 return new_ser .__finalize__ (self )
@@ -1413,7 +1415,7 @@ def repeat(self, repeats: int | Sequence[int], axis: None = None) -> Series:
14131415 nv .validate_repeat ((), {"axis" : axis })
14141416 new_index = self .index .repeat (repeats )
14151417 new_values = self ._values .repeat (repeats )
1416- return self ._constructor (new_values , index = new_index ).__finalize__ (
1418+ return self ._constructor (new_values , index = new_index , copy = False ).__finalize__ (
14171419 self , method = "repeat"
14181420 )
14191421
@@ -1579,7 +1581,7 @@ def reset_index(
15791581 self .index = new_index
15801582 else :
15811583 return self ._constructor (
1582- self ._values .copy (), index = new_index
1584+ self ._values .copy (), index = new_index , copy = False
15831585 ).__finalize__ (self , method = "reset_index" )
15841586 elif inplace :
15851587 raise TypeError (
@@ -2101,7 +2103,7 @@ def mode(self, dropna: bool = True) -> Series:
21012103
21022104 # Ensure index is type stable (should always use int index)
21032105 return self ._constructor (
2104- res_values , index = range (len (res_values )), name = self .name
2106+ res_values , index = range (len (res_values )), name = self .name , copy = False
21052107 )
21062108
21072109 def unique (self ) -> ArrayLike : # pylint: disable=useless-parent-delegation
@@ -2365,7 +2367,7 @@ def duplicated(self, keep: DropKeep = "first") -> Series:
23652367 dtype: bool
23662368 """
23672369 res = self ._duplicated (keep = keep )
2368- result = self ._constructor (res , index = self .index )
2370+ result = self ._constructor (res , index = self .index , copy = False )
23692371 return result .__finalize__ (self , method = "duplicated" )
23702372
23712373 def idxmin (self , axis : Axis = 0 , skipna : bool = True , * args , ** kwargs ) -> Hashable :
@@ -2543,7 +2545,7 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series:
25432545 """
25442546 nv .validate_round (args , kwargs )
25452547 result = self ._values .round (decimals )
2546- result = self ._constructor (result , index = self .index ).__finalize__ (
2548+ result = self ._constructor (result , index = self .index , copy = False ).__finalize__ (
25472549 self , method = "round"
25482550 )
25492551
@@ -2844,7 +2846,7 @@ def diff(self, periods: int = 1) -> Series:
28442846 {examples}
28452847 """
28462848 result = algorithms .diff (self ._values , periods )
2847- return self ._constructor (result , index = self .index ).__finalize__ (
2849+ return self ._constructor (result , index = self .index , copy = False ).__finalize__ (
28482850 self , method = "diff"
28492851 )
28502852
@@ -2962,7 +2964,7 @@ def dot(self, other: AnyArrayLike) -> Series | np.ndarray:
29622964
29632965 if isinstance (other , ABCDataFrame ):
29642966 return self ._constructor (
2965- np .dot (lvals , rvals ), index = other .columns
2967+ np .dot (lvals , rvals ), index = other .columns , copy = False
29662968 ).__finalize__ (self , method = "dot" )
29672969 elif isinstance (other , Series ):
29682970 return np .dot (lvals , rvals )
@@ -3264,7 +3266,7 @@ def combine(
32643266 # try_float=False is to match agg_series
32653267 npvalues = lib .maybe_convert_objects (new_values , try_float = False )
32663268 res_values = maybe_cast_pointwise_result (npvalues , self .dtype , same_dtype = False )
3267- return self ._constructor (res_values , index = new_index , name = new_name )
3269+ return self ._constructor (res_values , index = new_index , name = new_name , copy = False )
32683270
32693271 def combine_first (self , other ) -> Series :
32703272 """
@@ -3615,7 +3617,7 @@ def sort_values(
36153617 return self .copy (deep = None )
36163618
36173619 result = self ._constructor (
3618- self ._values [sorted_index ], index = self .index [sorted_index ]
3620+ self ._values [sorted_index ], index = self .index [sorted_index ], copy = False
36193621 )
36203622
36213623 if ignore_index :
@@ -3863,7 +3865,9 @@ def argsort(
38633865 else :
38643866 result = np .argsort (values , kind = kind )
38653867
3866- res = self ._constructor (result , index = self .index , name = self .name , dtype = np .intp )
3868+ res = self ._constructor (
3869+ result , index = self .index , name = self .name , dtype = np .intp , copy = False
3870+ )
38673871 return res .__finalize__ (self , method = "argsort" )
38683872
38693873 def nlargest (
@@ -4238,7 +4242,7 @@ def explode(self, ignore_index: bool = False) -> Series:
42384242 else :
42394243 index = self .index .repeat (counts )
42404244
4241- return self ._constructor (values , index = index , name = self .name )
4245+ return self ._constructor (values , index = index , name = self .name , copy = False )
42424246
42434247 def unstack (self , level : IndexLabel = - 1 , fill_value : Hashable = None ) -> DataFrame :
42444248 """
@@ -4369,7 +4373,7 @@ def map(
43694373 dtype: object
43704374 """
43714375 new_values = self ._map_values (arg , na_action = na_action )
4372- return self ._constructor (new_values , index = self .index ).__finalize__ (
4376+ return self ._constructor (new_values , index = self .index , copy = False ).__finalize__ (
43734377 self , method = "map"
43744378 )
43754379
@@ -4663,7 +4667,7 @@ def _reindex_indexer(
46634667 new_values = algorithms .take_nd (
46644668 self ._values , indexer , allow_fill = True , fill_value = None
46654669 )
4666- return self ._constructor (new_values , index = new_index )
4670+ return self ._constructor (new_values , index = new_index , copy = False )
46674671
46684672 def _needs_reindex_multi (self , axes , method , level ) -> bool :
46694673 """
@@ -5378,7 +5382,7 @@ def isin(self, values) -> Series:
53785382 dtype: bool
53795383 """
53805384 result = algorithms .isin (self ._values , values )
5381- return self ._constructor (result , index = self .index ).__finalize__ (
5385+ return self ._constructor (result , index = self .index , copy = False ).__finalize__ (
53825386 self , method = "isin"
53835387 )
53845388
0 commit comments