Skip to content

CoW: add readonly flag to ExtensionArrays, return read-only EA/ndarray in .array/EA.to_numpy() #61925

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
jorisvandenbossche committed Jul 22, 2025
commit 9cd6e4f39fc109ed5326606cb11c6905d8b34716
47 changes: 0 additions & 47 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,53 +515,6 @@ def __setitem__(self, key, value) -> None:

raise NotImplementedError(f"{type(self)} does not implement __setitem__.")

@property
def readonly(self) -> bool:
"""
Whether the array is readonly.

If True, attempts to modify the array via __setitem__ will raise
a ValueError.

Returns
-------
bool
True if the array is readonly, False otherwise.

Examples
--------
>>> arr = pd.array([1, 2, 3])
>>> arr.readonly
False
>>> arr.readonly = True
>>> arr[0] = 5
Traceback (most recent call last):
...
ValueError: Cannot modify readonly ExtensionArray
"""
return getattr(self, "_readonly", False)

@readonly.setter
def readonly(self, value: bool) -> None:
"""
Set the readonly state of the array.

Parameters
----------
value : bool
True to make the array readonly, False to make it writable.

Examples
--------
>>> arr = pd.array([1, 2, 3])
>>> arr.readonly = True
>>> arr.readonly
True
"""
if not isinstance(value, bool):
raise TypeError("readonly must be a boolean")
self._readonly = value

def __len__(self) -> int:
"""
Length of this array
Expand Down
Loading