-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update signature open_dataset for API v2 #4547
Changes from all commits
f961606
fb166fa
0221eec
36a02c7
cfb8cb8
4256bc8
1bc7391
748fe5a
fb368fe
80e111c
e15ca6b
025cc87
4b19399
572595f
d6e632e
74aba14
d6280ec
c0e0f34
6431101
50d1ebe
383d323
457a09c
2803fe3
08db0bd
1f11845
93303b1
bc2fe00
d694146
56f4d3f
df23b18
a04e6ac
de29a4c
be8c23b
feb486c
8f6af46
c9088d3
fe8099c
fed8b3e
6fec3ea
231895e
b88b567
be51bc7
5aa533d
7e75f1c
2047d46
3057abb
842fc29
ff1181c
bdcf0fe
61be8a8
c0b290a
c217031
8530ff0
73328ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import inspect | ||
import typing as T | ||
|
||
from . import cfgrib_, h5netcdf_, zarr | ||
|
||
ENGINES: T.Dict[str, T.Dict[str, T.Any]] = { | ||
"h5netcdf": { | ||
"open_dataset": h5netcdf_.open_backend_dataset_h5necdf, | ||
}, | ||
"zarr": { | ||
"open_dataset": zarr.open_backend_dataset_zarr, | ||
}, | ||
"cfgrib": { | ||
"open_dataset": cfgrib_.open_backend_dataset_cfgrib, | ||
}, | ||
} | ||
|
||
|
||
for engine in ENGINES.values(): | ||
if "signature" not in engine: | ||
parameters = inspect.signature(engine["open_dataset"]).parameters | ||
for name, param in parameters.items(): | ||
if param.kind in ( | ||
inspect.Parameter.VAR_KEYWORD, | ||
inspect.Parameter.VAR_POSITIONAL, | ||
): | ||
raise TypeError( | ||
f'All the parameters in {engine["open_dataset"]!r} signature should be explicit. ' | ||
"*args and **kwargs is not supported" | ||
) | ||
Comment on lines
+27
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it correctly implements my suggestion from last week 👍 . I don't know how annoying backend authors would find this restriction to be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the current implementation a backend developer can add the This allows also providing a I like the current implementation.
Comment on lines
+20
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's a lot of indentation! I think it might be a bit easier to read if we get rid of one level of indentation using if "signature" in engine:
continue nothing urgent, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are completely right! There is some style fix that I really need to do. I will do a new pull request. |
||
engine["signature"] = set(parameters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For completeness, let me mention an alternative design that would not need
inspect.signature
. Instead of using a single functionopen_backend_dataset
, we could use a "Loader" class with two separate methods, one for decoding a dataset and another for returning a raw dataset, e.g.,Is this better than the current approach in this PR (using inspect), or the current approach (on master) of calling the single
open_backend_dataset()
function withdecode_cf=False
? Honestly I'm not sure. It is most explicit, but also probably a little more annoying to write.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that in this way we are going to complicate the interface without a real advantage. But I'm not sure about it. @alexamici, @jhamman what do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shoyer the main reason we proposed the use
inspect
is to raise an appropriate error message when a backend doesn't support a specific decoding option.Your proposal simplifies the mangling of the decode options, but I'd still use
inspect
in the same as we do now before callingload_decode
.Personally I'd favour keeping the current implementation.