Skip to content

Commit 101786a

Browse files
committed
Fix condition for is_copy to avoid breaking other tests
1 parent ac08070 commit 101786a

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
@@ -3336,6 +3336,16 @@ class max_speed
33363336
1 monkey mammal NaN
33373337
3 lion mammal 80.5
33383338
"""
3339+
if is_copy is not None:
3340+
warnings.warn(
3341+
"is_copy is deprecated and will be removed in a future version. "
3342+
"take will always return a copy in the future.",
3343+
FutureWarning,
3344+
stacklevel=2,
3345+
)
3346+
else:
3347+
is_copy = True
3348+
33393349
nv.validate_take(tuple(), kwargs)
33403350

33413351
self._consolidate_inplace()
@@ -3346,17 +3356,9 @@ class max_speed
33463356
result = self._constructor(new_data).__finalize__(self)
33473357

33483358
# Maybe set copy if we didn't actually change the index.
3349-
if is_copy is not None:
3350-
warnings.warn(
3351-
"is_copy is deprecated and will be removed in a future version. "
3352-
"take will always return a copy in the future.",
3353-
FutureWarning,
3354-
stacklevel=2,
3355-
)
3359+
if is_copy:
33563360
if not result._get_axis(axis).equals(self._get_axis(axis)):
33573361
result._set_is_copy(self)
3358-
else:
3359-
is_copy = True
33603362

33613363
return result
33623364

@@ -4998,7 +5000,7 @@ def sample(
49985000
)
49995001

50005002
locs = rs.choice(axis_length, size=n, replace=replace, p=weights)
5001-
return self.take(locs, axis=axis)
5003+
return self.take(locs, is_copy=False, axis=axis)
50025004

50035005
_shared_docs[
50045006
"pipe"
@@ -6993,7 +6995,7 @@ def asof(self, where, subset=None):
69936995

69946996
# mask the missing
69956997
missing = locs == -1
6996-
data = self.take(locs)
6998+
data = self.take(locs, is_copy=False)
69976999
data.index = where
69987000
data.loc[missing] = np.nan
69997001
return data if is_list else data.iloc[-1]

0 commit comments

Comments
 (0)