Skip to content

Commit dabe051

Browse files
committed
Fix condition for is_copy to avoid breaking other tests
1 parent 9bd696c commit dabe051

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
@@ -3353,6 +3353,16 @@ class max_speed
33533353
1 monkey mammal NaN
33543354
3 lion mammal 80.5
33553355
"""
3356+
if is_copy is not None:
3357+
warnings.warn(
3358+
"is_copy is deprecated and will be removed in a future version. "
3359+
"take will always return a copy in the future.",
3360+
FutureWarning,
3361+
stacklevel=2,
3362+
)
3363+
else:
3364+
is_copy = True
3365+
33563366
nv.validate_take(tuple(), kwargs)
33573367

33583368
self._consolidate_inplace()
@@ -3363,17 +3373,9 @@ class max_speed
33633373
result = self._constructor(new_data).__finalize__(self)
33643374

33653375
# Maybe set copy if we didn't actually change the index.
3366-
if is_copy is not None:
3367-
warnings.warn(
3368-
"is_copy is deprecated and will be removed in a future version. "
3369-
"take will always return a copy in the future.",
3370-
FutureWarning,
3371-
stacklevel=2,
3372-
)
3376+
if is_copy:
33733377
if not result._get_axis(axis).equals(self._get_axis(axis)):
33743378
result._set_is_copy(self)
3375-
else:
3376-
is_copy = True
33773379

33783380
return result
33793381

@@ -5024,7 +5026,7 @@ def sample(
50245026
)
50255027

50265028
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
5027-
return self.take(locs, axis=axis)
5029+
return self.take(locs, is_copy=False, axis=axis)
50285030

50295031
_shared_docs[
50305032
"pipe"
@@ -7021,7 +7023,7 @@ def asof(self, where, subset=None):
70217023

70227024
# mask the missing
70237025
missing = locs == -1
7024-
data = self.take(locs)
7026+
data = self.take(locs, is_copy=False)
70257027
data.index = where
70267028
data.loc[missing] = np.nan
70277029
return data if is_list else data.iloc[-1]

0 commit comments

Comments
 (0)