Skip to content
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

Do not add variables/attributes to a Dataset that is used as input #254

Open
OnnoEbbens opened this issue Aug 25, 2023 · 5 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@OnnoEbbens
Copy link
Collaborator

There are some functions that (unexpectedly) modify the Dataset that is used as input for the function. Mostly because variables or attributes are added to the Dataset. For examples the functions. ds_to_rch, ds_to_evt and modelgrid_to_vertex_ds.

@OnnoEbbens OnnoEbbens self-assigned this Aug 25, 2023
@rubencalje
Copy link
Collaborator

Another example is set_ds_time.

So should we start these methods with a copy of the Dataset?

@dbrakenhoff
Copy link
Collaborator

If the method has "set_" in the name, I think this is ok, as the function name is pretty clear that it's setting something? But good to review whether this is the desired behavior.

@OnnoEbbens
Copy link
Collaborator Author

OnnoEbbens commented Aug 31, 2023

Depends on the function. In the case of set_ds_time I would say yes because we want to return the full dataset. In case of ds_to_rch and ds_to_evt I think we don't have to add anything to the dataset. For modelgrid_to_vertex_ds I think we should also make a copy.

A few problems may arise when creating a copy. If you make a shallow copy you will modify the dataset anyway. Making a deep copy may be time consuming. So we should look into this when making a copy.

@OnnoEbbens
Copy link
Collaborator Author

If the method has "set_" in the name, I think this is ok, as the function name is pretty clear that it's setting something? But good to review whether this is the desired behavior.

I agree with this as well. So we should not create a copy for function starting with set_...

Now that I examined modelgrid_to_vertex_ds better I think this function has become obsolete since we have the modelgrid_to_ds function which already deals with a vertex dataset.

@rubencalje
Copy link
Collaborator

rubencalje commented Sep 1, 2023

Yes , modelgrid_to_vertex_d can probably be removed. It could be used to add modelgrid-information to an existing Dataset (and not create a new Dataset like modelgrid_to_ds). I do not think we use it anywhere, and I do not see a use case for it.

@dbrakenhoff dbrakenhoff added the enhancement New feature or request label Nov 2, 2023
OnnoEbbens added a commit that referenced this issue Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants