@@ -840,7 +840,7 @@ def view(self, dtype: Dtype | None = None) -> Series:
840
840
# self.array instead of self._values so we piggyback on PandasArray
841
841
# implementation
842
842
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 )
844
844
if isinstance (res_ser ._mgr , SingleBlockManager ) and using_copy_on_write ():
845
845
blk = res_ser ._mgr ._block
846
846
blk .refs = cast ("BlockValuesRefs" , self ._references )
@@ -1073,7 +1073,7 @@ def _get_values_tuple(self, key: tuple):
1073
1073
1074
1074
# If key is contained, would have returned by now
1075
1075
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 )
1077
1077
if using_copy_on_write () and isinstance (indexer , slice ):
1078
1078
new_ser ._mgr .add_references (self ._mgr ) # type: ignore[arg-type]
1079
1079
return new_ser .__finalize__ (self )
@@ -1113,7 +1113,9 @@ def _get_value(self, label, takeable: bool = False):
1113
1113
1114
1114
new_index = mi [loc ]
1115
1115
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
+ )
1117
1119
if using_copy_on_write () and isinstance (loc , slice ):
1118
1120
new_ser ._mgr .add_references (self ._mgr ) # type: ignore[arg-type]
1119
1121
return new_ser .__finalize__ (self )
@@ -1413,7 +1415,7 @@ def repeat(self, repeats: int | Sequence[int], axis: None = None) -> Series:
1413
1415
nv .validate_repeat ((), {"axis" : axis })
1414
1416
new_index = self .index .repeat (repeats )
1415
1417
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__ (
1417
1419
self , method = "repeat"
1418
1420
)
1419
1421
@@ -1579,7 +1581,7 @@ def reset_index(
1579
1581
self .index = new_index
1580
1582
else :
1581
1583
return self ._constructor (
1582
- self ._values .copy (), index = new_index
1584
+ self ._values .copy (), index = new_index , copy = False
1583
1585
).__finalize__ (self , method = "reset_index" )
1584
1586
elif inplace :
1585
1587
raise TypeError (
@@ -2101,7 +2103,7 @@ def mode(self, dropna: bool = True) -> Series:
2101
2103
2102
2104
# Ensure index is type stable (should always use int index)
2103
2105
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
2105
2107
)
2106
2108
2107
2109
def unique (self ) -> ArrayLike : # pylint: disable=useless-parent-delegation
@@ -2365,7 +2367,7 @@ def duplicated(self, keep: DropKeep = "first") -> Series:
2365
2367
dtype: bool
2366
2368
"""
2367
2369
res = self ._duplicated (keep = keep )
2368
- result = self ._constructor (res , index = self .index )
2370
+ result = self ._constructor (res , index = self .index , copy = False )
2369
2371
return result .__finalize__ (self , method = "duplicated" )
2370
2372
2371
2373
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:
2543
2545
"""
2544
2546
nv .validate_round (args , kwargs )
2545
2547
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__ (
2547
2549
self , method = "round"
2548
2550
)
2549
2551
@@ -2844,7 +2846,7 @@ def diff(self, periods: int = 1) -> Series:
2844
2846
{examples}
2845
2847
"""
2846
2848
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__ (
2848
2850
self , method = "diff"
2849
2851
)
2850
2852
@@ -2962,7 +2964,7 @@ def dot(self, other: AnyArrayLike) -> Series | np.ndarray:
2962
2964
2963
2965
if isinstance (other , ABCDataFrame ):
2964
2966
return self ._constructor (
2965
- np .dot (lvals , rvals ), index = other .columns
2967
+ np .dot (lvals , rvals ), index = other .columns , copy = False
2966
2968
).__finalize__ (self , method = "dot" )
2967
2969
elif isinstance (other , Series ):
2968
2970
return np .dot (lvals , rvals )
@@ -3264,7 +3266,7 @@ def combine(
3264
3266
# try_float=False is to match agg_series
3265
3267
npvalues = lib .maybe_convert_objects (new_values , try_float = False )
3266
3268
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 )
3268
3270
3269
3271
def combine_first (self , other ) -> Series :
3270
3272
"""
@@ -3615,7 +3617,7 @@ def sort_values(
3615
3617
return self .copy (deep = None )
3616
3618
3617
3619
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
3619
3621
)
3620
3622
3621
3623
if ignore_index :
@@ -3863,7 +3865,9 @@ def argsort(
3863
3865
else :
3864
3866
result = np .argsort (values , kind = kind )
3865
3867
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
+ )
3867
3871
return res .__finalize__ (self , method = "argsort" )
3868
3872
3869
3873
def nlargest (
@@ -4238,7 +4242,7 @@ def explode(self, ignore_index: bool = False) -> Series:
4238
4242
else :
4239
4243
index = self .index .repeat (counts )
4240
4244
4241
- return self ._constructor (values , index = index , name = self .name )
4245
+ return self ._constructor (values , index = index , name = self .name , copy = False )
4242
4246
4243
4247
def unstack (self , level : IndexLabel = - 1 , fill_value : Hashable = None ) -> DataFrame :
4244
4248
"""
@@ -4369,7 +4373,7 @@ def map(
4369
4373
dtype: object
4370
4374
"""
4371
4375
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__ (
4373
4377
self , method = "map"
4374
4378
)
4375
4379
@@ -4663,7 +4667,7 @@ def _reindex_indexer(
4663
4667
new_values = algorithms .take_nd (
4664
4668
self ._values , indexer , allow_fill = True , fill_value = None
4665
4669
)
4666
- return self ._constructor (new_values , index = new_index )
4670
+ return self ._constructor (new_values , index = new_index , copy = False )
4667
4671
4668
4672
def _needs_reindex_multi (self , axes , method , level ) -> bool :
4669
4673
"""
@@ -5378,7 +5382,7 @@ def isin(self, values) -> Series:
5378
5382
dtype: bool
5379
5383
"""
5380
5384
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__ (
5382
5386
self , method = "isin"
5383
5387
)
5384
5388
0 commit comments