Skip to content

BUG: item_cache not cleared on DataFrame.values #34999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,7 @@ def to_numpy(
array([[1, 3.0, Timestamp('2000-01-01 00:00:00')],
[2, 4.5, Timestamp('2000-01-02 00:00:00')]], dtype=object)
"""
self._consolidate_inplace()
result = self._mgr.as_array(
transpose=self._AXIS_REVERSED, dtype=dtype, copy=copy, na_value=na_value
)
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5330,6 +5330,7 @@ def values(self) -> np.ndarray:
['lion', 80.5, 1],
['monkey', nan, None]], dtype=object)
"""
self._consolidate_inplace()
return self._mgr.as_array(transpose=self._AXIS_REVERSED)

@property
Expand Down Expand Up @@ -6526,7 +6527,7 @@ def replace(
f"Replacement lists must match in length. "
f"Expecting {len(to_replace)} got {len(value)} "
)

self._consolidate_inplace()
new_data = self._mgr.replace_list(
src_list=to_replace,
dest_list=value,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def as_array(
.values.to_numpy(dtype=dtype, na_value=na_value)
.reshape(self.blocks[0].shape)
)
elif self._is_single_block or not self.is_mixed_type:
elif self._is_single_block:
arr = np.asarray(self.blocks[0].get_values())
if dtype:
arr = arr.astype(dtype, copy=False)
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/frame/test_block_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ def test_modify_values(self, float_frame):

# unconsolidated
float_frame["E"] = 7.0
col = float_frame["E"]
float_frame.values[6] = 6
assert (float_frame.values[6] == 6).all()

# check that item_cache was cleared
assert float_frame["E"] is not col
assert (col == 7).all()

def test_boolean_set_uncons(self, float_frame):
float_frame["E"] = 7.0

Expand Down