-
-
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
Supplying a dataset to the dataset constructor #2330
Conversation
0d29ea9
to
3fee598
Compare
An alternative approach - more friendly but less explicit - is for any other argument (coords, attrs) supplied to overwrite the Dataset's |
I think this would be slightly preferred, and also more consistent with the model of a Dataset as only iterating over To be more precise, I would probably make:
equivalent to
|
OK good! And, to confirm, you think it's OK that :
|
Moving ahead with this, please let me know any objections from anyone |
I thought that |
Now I'm having second thoughts. It does make me a little nervous to add special cases that distinguish between Maybe my proposed solution above is too complex, and it would be better simply to default the That said, I do think we should try to resist the notion that every class constructor must also work for coercion to that class. This tends to result in a slightly confused interface. A separate |
From #2056 and this discussion I don't really understand the use case for this constructor - maybe an example of a real use case that could be added to the doc would help? |
@fmaussion good question The main reason I think this is worthwhile is the change in behavior between 0.10.x and 0.11.0, when iterating over a Dataset will iterate only over its To answer your question though, we hit this when inheriting from a Dataset: the object is initialized with a dataset, which is super-ed up to the Dataset constructor. (I realize this is narrow!). Alternatively, there is another repo that linked to the issue here |
I think we should do something here, rather than change behavior by coincidence. @shoyer do you want to make the decision? I would vote +0.1 for the current version in the PR. V happy to be outweighed! |
Any votes? I think the current version dominates the current master (i.e. it doesn't disable any useful functionality, it adds some clarity). So I would vote to merge unless anyone has any alternative suggestions (which I will gladly implement) Thanks team |
Sorry for taking so long here. I'm still not entirely comfortable with this change -- it adds some additional complexity to the
If I understand this correctly, you've written something like: class MyDataset(xarray.Dataset):
def __init__(self, dataset):
super().__init__(dataset) Is there any reason why you couldn't just write: class MyDataset(xarray.Dataset):
def __init__(self, dataset):
super().__init__(dataset.data_vars, dataset.coords, dataset.attrs)
I don't think it's quite a coincidence here -- we are changing the behavior of |
Yes, I agree - given the reluctance on the principle around "calling a constructor on an object of the same type needs to work" - it's right not to make this change. Thanks for holding that principle. I'll close this; let me know if there's any change around this I make in its place. |
Closes Warning on supplying a Dataset to the Dataset constructor #2056
Tests added (for all bug fixes or enhancements)
Tests passed (for all non-documentation changes)
Fully documented, including
whats-new.rst
for all changes andapi.rst
for new APIDo we want to raise if coords / attrs are passed in addition to a Dataset? Do we want to warn for a couple versions first?
Is this the best way to implement this? Do we want a consistent method to "make this object a shallow copy of the object that's been passed in"?