Skip to content

Commit 6507033

Browse files
committed
Fix condition for is_copy to avoid breaking other tests
1 parent 204e4c0 commit 6507033

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

pandas/core/generic.py

Lines changed: 13 additions & 11 deletions
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

@@ -5012,7 +5014,7 @@ def sample(
50125014
)
50135015

50145016
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
5015-
return self.take(locs, axis=axis)
5017+
return self.take(locs, is_copy=False, axis=axis)
50165018

50175019
_shared_docs[
50185020
"pipe"
@@ -7009,7 +7011,7 @@ def asof(self, where, subset=None):
70097011

70107012
# mask the missing
70117013
missing = locs == -1
7012-
data = self.take(locs)
7014+
data = self.take(locs, is_copy=False)
70137015
data.index = where
70147016
data.loc[missing] = np.nan
70157017
return data if is_list else data.iloc[-1]

0 commit comments

Comments
 (0)