@@ -843,7 +843,7 @@ def view(self, dtype: Dtype | None = None) -> Series:
843
843
# self.array instead of self._values so we piggyback on PandasArray
844
844
# implementation
845
845
res_values = self .array .view (dtype )
846
- res_ser = self ._constructor (res_values , index = self .index )
846
+ res_ser = self ._constructor (res_values , index = self .index , copy = False )
847
847
if isinstance (res_ser ._mgr , SingleBlockManager ) and using_copy_on_write ():
848
848
blk = res_ser ._mgr ._block
849
849
blk .refs = cast ("BlockValuesRefs" , self ._references )
@@ -1044,7 +1044,7 @@ def _get_values_tuple(self, key: tuple):
1044
1044
1045
1045
# If key is contained, would have returned by now
1046
1046
indexer , new_index = self .index .get_loc_level (key )
1047
- new_ser = self ._constructor (self ._values [indexer ], index = new_index )
1047
+ new_ser = self ._constructor (self ._values [indexer ], index = new_index , copy = False )
1048
1048
if using_copy_on_write () and isinstance (indexer , slice ):
1049
1049
new_ser ._mgr .add_references (self ._mgr ) # type: ignore[arg-type]
1050
1050
return new_ser .__finalize__ (self )
@@ -1084,7 +1084,9 @@ def _get_value(self, label, takeable: bool = False):
1084
1084
1085
1085
new_index = mi [loc ]
1086
1086
new_index = maybe_droplevels (new_index , label )
1087
- new_ser = self ._constructor (new_values , index = new_index , name = self .name )
1087
+ new_ser = self ._constructor (
1088
+ new_values , index = new_index , name = self .name , copy = False
1089
+ )
1088
1090
if using_copy_on_write () and isinstance (loc , slice ):
1089
1091
new_ser ._mgr .add_references (self ._mgr ) # type: ignore[arg-type]
1090
1092
return new_ser .__finalize__ (self )
@@ -1384,7 +1386,7 @@ def repeat(self, repeats: int | Sequence[int], axis: None = None) -> Series:
1384
1386
nv .validate_repeat ((), {"axis" : axis })
1385
1387
new_index = self .index .repeat (repeats )
1386
1388
new_values = self ._values .repeat (repeats )
1387
- return self ._constructor (new_values , index = new_index ).__finalize__ (
1389
+ return self ._constructor (new_values , index = new_index , copy = False ).__finalize__ (
1388
1390
self , method = "repeat"
1389
1391
)
1390
1392
@@ -1550,7 +1552,7 @@ def reset_index(
1550
1552
self .index = new_index
1551
1553
else :
1552
1554
return self ._constructor (
1553
- self ._values .copy (), index = new_index
1555
+ self ._values .copy (), index = new_index , copy = False
1554
1556
).__finalize__ (self , method = "reset_index" )
1555
1557
elif inplace :
1556
1558
raise TypeError (
@@ -2072,7 +2074,7 @@ def mode(self, dropna: bool = True) -> Series:
2072
2074
2073
2075
# Ensure index is type stable (should always use int index)
2074
2076
return self ._constructor (
2075
- res_values , index = range (len (res_values )), name = self .name
2077
+ res_values , index = range (len (res_values )), name = self .name , copy = False
2076
2078
)
2077
2079
2078
2080
def unique (self ) -> ArrayLike : # pylint: disable=useless-parent-delegation
@@ -2336,7 +2338,7 @@ def duplicated(self, keep: DropKeep = "first") -> Series:
2336
2338
dtype: bool
2337
2339
"""
2338
2340
res = self ._duplicated (keep = keep )
2339
- result = self ._constructor (res , index = self .index )
2341
+ result = self ._constructor (res , index = self .index , copy = False )
2340
2342
return result .__finalize__ (self , method = "duplicated" )
2341
2343
2342
2344
def idxmin (self , axis : Axis = 0 , skipna : bool = True , * args , ** kwargs ) -> Hashable :
@@ -2514,7 +2516,7 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series:
2514
2516
"""
2515
2517
nv .validate_round (args , kwargs )
2516
2518
result = self ._values .round (decimals )
2517
- result = self ._constructor (result , index = self .index ).__finalize__ (
2519
+ result = self ._constructor (result , index = self .index , copy = False ).__finalize__ (
2518
2520
self , method = "round"
2519
2521
)
2520
2522
@@ -2820,7 +2822,7 @@ def diff(self, periods: int = 1) -> Series:
2820
2822
{examples}
2821
2823
"""
2822
2824
result = algorithms .diff (self ._values , periods )
2823
- return self ._constructor (result , index = self .index ).__finalize__ (
2825
+ return self ._constructor (result , index = self .index , copy = False ).__finalize__ (
2824
2826
self , method = "diff"
2825
2827
)
2826
2828
@@ -2938,7 +2940,7 @@ def dot(self, other: AnyArrayLike) -> Series | np.ndarray:
2938
2940
2939
2941
if isinstance (other , ABCDataFrame ):
2940
2942
return self ._constructor (
2941
- np .dot (lvals , rvals ), index = other .columns
2943
+ np .dot (lvals , rvals ), index = other .columns , copy = False
2942
2944
).__finalize__ (self , method = "dot" )
2943
2945
elif isinstance (other , Series ):
2944
2946
return np .dot (lvals , rvals )
@@ -3167,7 +3169,7 @@ def combine(
3167
3169
# try_float=False is to match agg_series
3168
3170
npvalues = lib .maybe_convert_objects (new_values , try_float = False )
3169
3171
res_values = maybe_cast_pointwise_result (npvalues , self .dtype , same_dtype = False )
3170
- return self ._constructor (res_values , index = new_index , name = new_name )
3172
+ return self ._constructor (res_values , index = new_index , name = new_name , copy = False )
3171
3173
3172
3174
def combine_first (self , other ) -> Series :
3173
3175
"""
@@ -3528,7 +3530,7 @@ def sort_values(
3528
3530
return self .copy (deep = None )
3529
3531
3530
3532
result = self ._constructor (
3531
- self ._values [sorted_index ], index = self .index [sorted_index ]
3533
+ self ._values [sorted_index ], index = self .index [sorted_index ], copy = False
3532
3534
)
3533
3535
3534
3536
if ignore_index :
@@ -3776,7 +3778,9 @@ def argsort(
3776
3778
else :
3777
3779
result = np .argsort (values , kind = kind )
3778
3780
3779
- res = self ._constructor (result , index = self .index , name = self .name , dtype = np .intp )
3781
+ res = self ._constructor (
3782
+ result , index = self .index , name = self .name , dtype = np .intp , copy = False
3783
+ )
3780
3784
return res .__finalize__ (self , method = "argsort" )
3781
3785
3782
3786
def nlargest (
@@ -4151,7 +4155,7 @@ def explode(self, ignore_index: bool = False) -> Series:
4151
4155
else :
4152
4156
index = self .index .repeat (counts )
4153
4157
4154
- return self ._constructor (values , index = index , name = self .name )
4158
+ return self ._constructor (values , index = index , name = self .name , copy = False )
4155
4159
4156
4160
def unstack (self , level : IndexLabel = - 1 , fill_value : Hashable = None ) -> DataFrame :
4157
4161
"""
@@ -4282,7 +4286,7 @@ def map(
4282
4286
dtype: object
4283
4287
"""
4284
4288
new_values = self ._map_values (arg , na_action = na_action )
4285
- return self ._constructor (new_values , index = self .index ).__finalize__ (
4289
+ return self ._constructor (new_values , index = self .index , copy = False ).__finalize__ (
4286
4290
self , method = "map"
4287
4291
)
4288
4292
@@ -4576,7 +4580,7 @@ def _reindex_indexer(
4576
4580
new_values = algorithms .take_nd (
4577
4581
self ._values , indexer , allow_fill = True , fill_value = None
4578
4582
)
4579
- return self ._constructor (new_values , index = new_index )
4583
+ return self ._constructor (new_values , index = new_index , copy = False )
4580
4584
4581
4585
def _needs_reindex_multi (self , axes , method , level ) -> bool :
4582
4586
"""
@@ -5291,7 +5295,7 @@ def isin(self, values) -> Series:
5291
5295
dtype: bool
5292
5296
"""
5293
5297
result = algorithms .isin (self ._values , values )
5294
- return self ._constructor (result , index = self .index ).__finalize__ (
5298
+ return self ._constructor (result , index = self .index , copy = False ).__finalize__ (
5295
5299
self , method = "isin"
5296
5300
)
5297
5301
0 commit comments