Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ed966dd

Browse filesBrowse files
REGR: where not copying on no-op (#40592) (#40634)
Co-authored-by: Matthew Zeitlin <37011898+mzeitlin11@users.noreply.github.com>
1 parent 97f9a1e commit ed966dd
Copy full SHA for ed966dd

File tree

Expand file treeCollapse file tree

3 files changed

+19
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+19
-1
lines changed

‎doc/source/whatsnew/v1.2.4.rst

Copy file name to clipboardExpand all lines: doc/source/whatsnew/v1.2.4.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Fixed regressions
1717

1818
- Fixed regression in :meth:`DataFrame.sum` when ``min_count`` greater than the :class:`DataFrame` shape was passed resulted in a ``ValueError`` (:issue:`39738`)
1919
- Fixed regression in :meth:`DataFrame.to_json` raising ``AttributeError`` when run on PyPy (:issue:`39837`)
20+
- Fixed regression in :meth:`DataFrame.where` not returning a copy in the case of an all True condition (:issue:`39595`)
2021
-
2122

2223
.. ---------------------------------------------------------------------------

‎pandas/core/internals/blocks.py

Copy file name to clipboardExpand all lines: pandas/core/internals/blocks.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ def where(
14581458
raise ValueError("where must have a condition that is ndarray like")
14591459

14601460
if cond.ravel("K").all():
1461-
result = values
1461+
result = values.copy()
14621462
else:
14631463
# see if we can operate on the entire block, or need item-by-item
14641464
# or if we are a single block (ndim == 1)

‎pandas/tests/frame/indexing/test_where.py

Copy file name to clipboardExpand all lines: pandas/tests/frame/indexing/test_where.py
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,20 @@ def test_where_categorical_filtering(self):
653653
expected.loc[0, :] = np.nan
654654

655655
tm.assert_equal(result, expected)
656+
657+
658+
def test_where_copies_with_noop(frame_or_series):
659+
# GH-39595
660+
result = frame_or_series([1, 2, 3, 4])
661+
expected = result.copy()
662+
col = result[0] if frame_or_series is DataFrame else result
663+
664+
where_res = result.where(col < 5)
665+
where_res *= 2
666+
667+
tm.assert_equal(result, expected)
668+
669+
where_res = result.where(col > 5, [1, 2, 3, 4])
670+
where_res *= 2
671+
672+
tm.assert_equal(result, expected)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.