Skip to content

Add back getattr for ExtensionArrays #10278

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 8 commits into from
May 8, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Update xarray/core/extension_array.py
Co-authored-by: Ilan Gold <ilanbassgold@gmail.com>
  • Loading branch information
dcherian and ilan-gold authored May 8, 2025
commit 93405b81ab62468d29f0d0f1c952f6a7aaf3e295
11 changes: 4 additions & 7 deletions xarray/core/extension_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,8 @@ def __array__(
return np.asarray(self.array, dtype=dtype)

def __getattr__(self, attr: str) -> Any:
# without __deepcopy__ or __copy__, the object is first constructed and then the sub-objects are attached:
# "A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original" +
# "A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original."
# So without array, this method then calls getattr for "array" again while looking for __setstate__
# (which is apparently the first thing sought in copy.copy from the under-construction copied object)
# because of self.array. __getattribute__ bypasses the lookup mechanism of __getattr__.
# See stackoverflow.com/questions/40583131/python-deepcopy-with-custom-getattr-and-setattr as well.
# with __deepcopy__ or __copy__, the object is first constructed and then the sub-objects are attached (see https://docs.python.org/3/library/copy.html)
# Thus, if we didn't have `super().__getattribute__("array")` this method would call `self.array` (i.e., `getattr(self, "array")`) again while looking for `__setstate__`
# (which is apparently the first thing sought in copy.copy from the under-construction copied object),
# which would cause a recursion error since `array` is not present on the object when it is being constructed during `__{deep}copy__`.
return getattr(super().__getattribute__("array"), attr)
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy