diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 70019030da182..2052d84b1e6ff 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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) ) diff --git a/pandas/tests/copy_view/test_methods.py b/pandas/tests/copy_view/test_methods.py index 00ac06295572f..399c7cbef2009 100644 --- a/pandas/tests/copy_view/test_methods.py +++ b/pandas/tests/copy_view/test_methods.py @@ -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()