pydata / pydata/xarray

`NamedArray` typing audit

Open
#10,036 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement topic-NamedArray topic-typing
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What is your issue?

See: https://github.com/pydata/xarray/pull/9671#issuecomment-2642542167

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:

https://github.com/pydata/xarray/blob/d57f05c1a405dc8541fff3c92a5d9577a6df1d5b/xarray/namedarray/_typing.py#L188-L192

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with xarray/namedarray/_typing.py at lines 188-192 and read the linked PR comment. Compare the declared NamedArray backing-data contract with the behavior of PandasIndexingAdapter, PandasExtensionArray, and NumPy arrays, including the dtype and getitem/array concerns. Done means the typing model accurately reflects these implementations and the remaining design is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, python
Domain
data, developer-experience
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.