Skip to content

Typing is not correct for bracket-notation access for a Dataset variable #8046

Closed Answered by TomNicholas
eschalkargans asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, welcome! 👋

If I understand your question correctly, you want to know why the return type of the dot notation is Any. The answer is because the dot notation can also be used to access the attributes dictionary on xarray objects, which can store arbitary metadata. For example in this case the return type is a string:

In [1]: import xarray as xr

In [2]: da = xr.DataArray(0, attrs={'t' : 'calendar'})

In [3]: da.t
Out[3]: 'calendar'

So, does the xarray community recommends to favor bracket notation over dot notation to enforce type hinting in projects, and favor dot notation for shorter feedback loops (debugging, jupyter notebooks) where static typing is less important than type speed?

E…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by eschalkargans
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants