Skip to content
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

NamedArray typing audit #10036

Open
ilan-gold opened this issue Feb 7, 2025 · 2 comments
Open

NamedArray typing audit #10036

ilan-gold opened this issue Feb 7, 2025 · 2 comments
Labels
enhancement topic-NamedArray Lightweight version of Variable topic-typing

Comments

@ilan-gold
Copy link
Contributor

What is your issue?

See: #9671 (comment)

At the moment, NamedArray's backing data can fulfill _arrayfunction although in practice, PandasIndexingAdapter and PandasExtensionArray don't actually fulfill this contract (although the later is much closer than the former). The following two lines are particularly problematic for non-numeric data:

@property
def imag(self) -> _arrayfunction[_ShapeType_co, Any]: ...
@property
def real(self) -> _arrayfunction[_ShapeType_co, Any]: ...

FWIW numpy arrays do always fulfill this even when it doesn't make sense (even object dtypes have a imag and real). So I'm not sure how to move forward.

Of course, another issue is the whole _DType_co being bound to numpy. __getitem__ can return pandas dtypes but __array__ won't so maybe we need a base dtype and then a numpy one as well in the generic for the class?

@ilan-gold ilan-gold added the needs triage Issue that has not been reviewed by xarray team member label Feb 7, 2025
@Illviljan
Copy link
Contributor

For imag and real: #9368 (Been some iterations on this topic, #8295, #8365)

For the dtype issues I've made an attempt in #8933, but as usual it's not that easy to just switch to a simpler dtype class.

@headtr1ck
Copy link
Collaborator

For the dtype issue I guess we will run into the problem of not having higher kinded types.

Not sure how one could solve that without some ugly descriptors.

@headtr1ck headtr1ck added topic-typing topic-NamedArray Lightweight version of Variable enhancement and removed needs triage Issue that has not been reviewed by xarray team member labels Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement topic-NamedArray Lightweight version of Variable topic-typing
Projects
None yet
Development

No branches or pull requests

3 participants