Switch to T_DataArray in .coords#7285
Conversation
| def __getitem__(self, key: Hashable) -> T_DataArray: | ||
| return self._data._getitem_coord(key) |
There was a problem hiding this comment.
xarray/core/coordinates.py:372: error: A function returning TypeVar should receive at least one argument containing the same Typevar [type-var]
xarray/core/coordinates.py:372: note: Consider using the upper bound "DataArray" insteadI don't really understand this error, why should the method have at least one argument with the same TypeVar? The TypeVar is stored in self already.
There was a problem hiding this comment.
That's what I meant with making coordinates a generic class.
There was a problem hiding this comment.
Sorry, I'm not following. Feel free to push to this PR or link me to an example you think is similar.
There was a problem hiding this comment.
Ok, nvmd. This does not seem to work in python 3.8....
Anyone has an idea how to solve this? haha.
There was a problem hiding this comment.
Yeah, a little surprised it worked. :D
Taken from:
https://github.com/python/cpython/blob/b0e1f9c241cd8f8c864d51059217f997d3b792bf/Lib/_collections_abc.py#L428
There was a problem hiding this comment.
Does it work though? What does a reveal_type(da.coords) give?
Or a reveal_type(da.coords["x"])?
There was a problem hiding this comment.
I get this on main:
da = xr.DataArray()
reveal_type(da) # note: Revealed type is "Any"Do you as well?
There was a problem hiding this comment.
No, I get note: Revealed type is "xarray.core.dataarray.DataArray" as expected.
(python 3.9.13 and mypy 0.990)
There was a problem hiding this comment.
Hmm, I use:
mypy 0.982 py310h8d17308_0 conda-forge
mypy_extensions 0.4.3 py310h5588dad_5 conda-forge
...
python 3.10.6 h9a09f29_0_cpython conda-forge
|
Mypy errors with python 3.8. Doesn't appear related to this PR at least. |
|
See #6963 for python 3.8 |
|
Just noticed that now pylance and mypy return "Any" as Value types. |
* upstream/main: (39 commits) Support the new compression argument in netCDF4 > 1.6.0 (pydata#6981) Remove setuptools-scm-git-archive, require setuptools-scm>=7 (pydata#7253) Fix mypy failures (pydata#7343) Docs: add example of writing and reading groups to netcdf (pydata#7338) Reset file pointer to 0 when reading file stream (pydata#7304) Enable mypy warn unused ignores (pydata#7335) Optimize some copying (pydata#7209) Add parse_dims func (pydata#7051) Fix coordinate attr handling in `xr.where(..., keep_attrs=True)` (pydata#7229) Remove code used to support h5py<2.10.0 (pydata#7334) [pre-commit.ci] pre-commit autoupdate (pydata#7330) Fix PR number in what’s new (pydata#7331) Enable `origin` and `offset` arguments in `resample` (pydata#7284) fix doctests: supress urllib3 warning (pydata#7326) fix flake8 config (pydata#7321) implement Zarr v3 spec support (pydata#6475) Fix polyval overloads (pydata#7315) deprecate pynio backend (pydata#7301) mypy - Remove some ignored packages and modules (pydata#7319) Switch to T_DataArray in .coords (pydata#7285) ...
.coords were still using DataArray types switch to T_DataArray instead.