Closed malmans2 closed 1 month ago
Thanks for reporting this issue. This should not crash, however, the reader is an internal object and should not be used like that, since the underlying code can be refactored any time. To overcome this I'd rather add a method to the object returned from from_source()
to perform the checks you need.
OK, thanks!
For context, the kwargs
accepted by to_xarray
are not fixed (e.g., csv doesn't accept open_mfdataset
kwargs but accepts pandas read_csv
kwargs). Furthermore, earthkit changes the default of xarray's backend-specific kwargs (e.g., the use of squeeze=False
for cfgrib
is not compatible with our code).
We need a way to discriminate which kwargs we can pass to to_xarray
.
OK, thanks!
For context, the
kwargs
accepted byto_xarray
are not fixed (e.g., csv doesn't acceptopen_mfdataset
kwargs but accepts pandasread_csv
kwargs). Furthermore, earthkit changes the default of xarray's backend-specific kwargs (e.g., the use ofsqueeze=False
forcfgrib
is not compatible with our code).We need a way to discriminate which kwargs we can pass to
to_xarray
.
I am not sure this comment belongs to this issue.
the reader is an internal object and should not be used like that, since the underlying code can be refactored any time. To overcome this I'd rather add a method to the object returned from from_source() to perform the checks you need.
I just wanted to provide more details about the use we are doing as you mentioned that we should not import the reader class and a new method will be added:
if isinstance(earthkit_ds, GRIBReader):
xr_ds = earthkit_ds.to_xarray(xarray_open_dataset_kwargs={"squeeze": False, "chunks": {}})
elif isinstance(earthkit_ds, CSVReader):
xr_ds = ds.to_xarray(pandas_read_csv_kwargs=...)
elif ...:
...
else:
xr_ds = earthkit_ds.to_xarray(xarray_open_mfdataset_kwargs=...)
What happened?
I need to check in my code the object instantiated by
from_source
. For example, I need to do this:isinstance(ds, GRIBReader)
However, when I import the readerfrom_source
breaks.What are the steps to reproduce the bug?
Version
0.7.0
Platform (OS and architecture)
Linux eqc-quality-tools.eqc.compute.cci1.ecmwf.int 5.14.0-362.8.1.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 8 17:36:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Relevant log output
Accompanying data
No response
Organisation
B-Open / CADS-EQC