You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe it should be another rioxarray function that can open datasets grouped by resolution.
I think I get the idea of "why" it is like this, but I still think it's not very convenient when developing. That's why I consider it an improvement if it could work differently. Like with rioxarray.open_dataset and then rioxarray.open_groups or else.
@snowman2 one can probably use @overload annotations to support DataArray vs Dataset|list[Dataset] disambiguation, switched on literal value passed to band_as_variable= parameter, they are a bit of pain to maintain when there are a lot of common arguments though.
here is an example use from odc-geo, that allows us to know that norm_crs(None|Unset()) -> None, and hence any other input should be producing CRS and not CRS|None:
Unfortunately for me this was not a drop-in replacement for open_rasterio with single band tiffs, I ended up with ValueError: cannot convert float NaN to integer which I wasn't going to chase down. Instead I kept pyright happy with a type check:
da = rioxarray.open_rasterio(path)
if not isinstance(da, DataArray):
raise ValueError(f"Unexpected return type from open_rasterio: {da}")
Activity
snowman2 commentedon Apr 30, 2025
Not all datasets have uniform resolutions. Due to this, a list can be returned with datasets grouped by resolution:
https://github.com/corteva/rioxarray/blob/2a1f01e6fd141bdb1f87f4222165cf34f517dd97/test/integration/test_integration__io.py#L224
renaudjester commentedon Apr 30, 2025
Maybe it should be another
rioxarrayfunction that can open datasets grouped by resolution.I think I get the idea of "why" it is like this, but I still think it's not very convenient when developing. That's why I consider it an improvement if it could work differently. Like with
rioxarray.open_datasetand thenrioxarray.open_groupsor else.snowman2 commentedon Apr 30, 2025
The interface you want already exists:
renaudjester commentedon Apr 30, 2025
True! I will be using this then! Thanks for your answer, feel free to close this issue if you think that this is enough! Have a great day!
Kirill888 commentedon May 1, 2025
@snowman2 one can probably use
@overloadannotations to supportDataArrayvsDataset|list[Dataset]disambiguation, switched on literal value passed toband_as_variable=parameter, they are a bit of pain to maintain when there are a lot of common arguments though.here is an example use from
odc-geo, that allows us to know thatnorm_crs(None|Unset()) -> None, and hence any other input should be producingCRSand notCRS|None:snowman2 commentedon May 1, 2025
The return type is determined by the contents of the file and not by a kwarg. So, overload likely won't help in this situation.
cas-- commentedon Jun 3, 2025
Unfortunately for me this was not a drop-in replacement for
open_rasteriowith single band tiffs, I ended up withValueError: cannot convert float NaN to integerwhich I wasn't going to chase down. Instead I kept pyright happy with a type check:acoque commentedon Nov 18, 2025
@snowman2 I think returning a
DataTreeinstead of a list ofDatasetwould be nice, right? + it would solve @renaudjester's issue 🤔snowman2 commentedon Nov 18, 2025
Yes, that would be way better. The method pre-dates
DataTreein xarray, but I think it is time for an upgrade 😄. Contributions welcome!