@@ -812,7 +812,7 @@ def is_writeable_array(x):
812
812
return False
813
813
return True
814
814
815
- def _parse_copy_param (x , copy : bool | None ) -> bool :
815
+ def _parse_copy_param (x , copy : bool | None | Literal [ "_force_false" ] ) -> bool :
816
816
"""Preprocess and validate a copy parameter, in line with the same
817
817
parameter in np.asarray(), np.astype(), etc.
818
818
"""
@@ -821,6 +821,8 @@ def _parse_copy_param(x, copy: bool | None) -> bool:
821
821
if copy is False :
822
822
if not is_writeable_array (x ):
823
823
raise ValueError ("Cannot avoid modifying parameter in place" )
824
+ elif copy == "_force_false" :
825
+ return False
824
826
elif copy is not True :
825
827
raise ValueError (f"Invalid value for copy: { copy !r} " )
826
828
return copy
@@ -909,7 +911,7 @@ def _common(
909
911
self ,
910
912
at_op : str ,
911
913
y = _undef ,
912
- copy : bool | None = True ,
914
+ copy : bool | None | Literal [ "_force_false" ] = True ,
913
915
** kwargs ,
914
916
):
915
917
"""Validate kwargs and perform common prepocessing.
@@ -956,13 +958,13 @@ def get(self, copy: bool | None = True, **kwargs):
956
958
or (is_numpy_array (self .idx ) and self .idx .dtype .kind in "biu" )
957
959
)
958
960
):
959
- if copy is True :
960
- copy = None
961
- elif copy is False :
961
+ if copy is False :
962
962
raise ValueError (
963
963
"Indexing a numpy array with a fancy index always "
964
964
"results in a copy"
965
965
)
966
+ # Skip copy inside _common, even if array is not writeable
967
+ copy = "_force_false" # type: ignore
966
968
967
969
res , x = self ._common ("get" , copy = copy , ** kwargs )
968
970
if res is not None :
0 commit comments