Skip to content

BUG: Count creates result with read_only array #51943

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 2 commits into from
Mar 14, 2023
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
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10870,7 +10870,7 @@ def count(self, axis: Axis = 0, numeric_only: bool = False):
else:
# GH13407
series_counts = notna(frame).sum(axis=axis)
counts = series_counts.values
counts = series_counts._values
result = self._constructor_sliced(
counts, index=frame._get_agg_axis(axis)
)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/copy_view/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,14 @@ def test_transpose_ea_single_column(using_copy_on_write):
assert not np.shares_memory(get_array(df, "a"), get_array(result, 0))


def test_count_read_only_array():
df = DataFrame({"a": [1, 2], "b": 3})
result = df.count()
result.iloc[0] = 100
expected = Series([100, 2], index=["a", "b"])
tm.assert_series_equal(result, expected)


def test_series_view(using_copy_on_write):
ser = Series([1, 2, 3])
ser_orig = ser.copy()
Expand Down