Skip to content

Commit 837107c

Browse files
committed
Fix condition for is_copy to avoid breaking other tests
1 parent 6625250 commit 837107c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

pandas/core/generic.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -3341,6 +3341,16 @@ class max_speed
33413341
1 monkey mammal NaN
33423342
3 lion mammal 80.5
33433343
"""
3344+
if is_copy is not None:
3345+
warnings.warn(
3346+
"is_copy is deprecated and will be removed in a future version. "
3347+
"take will always return a copy in the future.",
3348+
FutureWarning,
3349+
stacklevel=2,
3350+
)
3351+
else:
3352+
is_copy = True
3353+
33443354
nv.validate_take(tuple(), kwargs)
33453355

33463356
self._consolidate_inplace()
@@ -3351,17 +3361,9 @@ class max_speed
33513361
result = self._constructor(new_data).__finalize__(self)
33523362

33533363
# Maybe set copy if we didn't actually change the index.
3354-
if is_copy is not None:
3355-
warnings.warn(
3356-
"is_copy is deprecated and will be removed in a future version. "
3357-
"take will always return a copy in the future.",
3358-
FutureWarning,
3359-
stacklevel=2,
3360-
)
3364+
if is_copy:
33613365
if not result._get_axis(axis).equals(self._get_axis(axis)):
33623366
result._set_is_copy(self)
3363-
else:
3364-
is_copy = True
33653367

33663368
return result
33673369

@@ -5007,7 +5009,7 @@ def sample(
50075009
)
50085010

50095011
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
5010-
return self.take(locs, axis=axis)
5012+
return self.take(locs, is_copy=False, axis=axis)
50115013

50125014
_shared_docs[
50135015
"pipe"
@@ -7004,7 +7006,7 @@ def asof(self, where, subset=None):
70047006

70057007
# mask the missing
70067008
missing = locs == -1
7007-
data = self.take(locs)
7009+
data = self.take(locs, is_copy=False)
70087010
data.index = where
70097011
data.loc[missing] = np.nan
70107012
return data if is_list else data.iloc[-1]

0 commit comments

Comments
 (0)