Skip to content

Commit e316f5d

Browse files
authored
BUG: Count creates result with read_only array (#51943)
1 parent 425c601 commit e316f5d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10870,7 +10870,7 @@ def count(self, axis: Axis = 0, numeric_only: bool = False):
1087010870
else:
1087110871
# GH13407
1087210872
series_counts = notna(frame).sum(axis=axis)
10873-
counts = series_counts.values
10873+
counts = series_counts._values
1087410874
result = self._constructor_sliced(
1087510875
counts, index=frame._get_agg_axis(axis)
1087610876
)

pandas/tests/copy_view/test_methods.py

+8
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,14 @@ def test_transpose_ea_single_column(using_copy_on_write):
16741674
assert not np.shares_memory(get_array(df, "a"), get_array(result, 0))
16751675

16761676

1677+
def test_count_read_only_array():
1678+
df = DataFrame({"a": [1, 2], "b": 3})
1679+
result = df.count()
1680+
result.iloc[0] = 100
1681+
expected = Series([100, 2], index=["a", "b"])
1682+
tm.assert_series_equal(result, expected)
1683+
1684+
16771685
def test_series_view(using_copy_on_write):
16781686
ser = Series([1, 2, 3])
16791687
ser_orig = ser.copy()

0 commit comments

Comments
 (0)