-
Notifications
You must be signed in to change notification settings - Fork 57
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
Fix keepdims #778
Fix keepdims #778
Conversation
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.
Great
See comments and decide if you want to change :-)
mikeio/__init__.py
Outdated
|
||
dfs = open(filename) | ||
if isinstance(dfs, Mesh): | ||
raise ValueError("mikeio.read() is not supported for Mesh files") | ||
assert not isinstance(dfs, Mesh) |
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.
I do not understand this change - isn't the user better supported by a ValueError with a clear error message?
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.
True
mikeio/dfs/_dfs.py
Outdated
shape = (nt, self.nz, self.ny, self.nx) # type: ignore | ||
|
||
spdims = self.geometry.default_dims | ||
dims = ["time"] |
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 a little confusing to me to first always prepend dims with "time" and then afterwards potentially removing it in line 403 🤔 But it looks like it works and you have probably considered alternative ways.
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.
There is room for improvement...
mikeio/dfs/_dfs.py
Outdated
|
||
d[d == self.deletevalue] = np.nan | ||
|
||
if self._ndim == 2: | ||
d = d.reshape(self.ny, self.nx) # type: ignore | ||
|
||
if single_time_selected: | ||
data_list[item] = d | ||
if keepdims: |
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.
Why not
data_list[item] = np.atleast_2d(d) if keepdims else d
@@ -574,3 +574,38 @@ def test_concat_dfsu3d_single_timesteps_generic_vs_dataset(tmp_path): | |||
assert ds3.end_time == ds4.end_time | |||
assert ds3.n_items == ds4.n_items | |||
assert ds3.n_timesteps == ds4.n_timesteps | |||
|
|||
|
|||
def test_keepdims_removes_singleton_dimension() -> None: |
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.
Great tests ❤️
And I guess it is not relevant to add one with dfs0 or dfs3? (what happens with the keepdims argument then)
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.
I suppose dfs3 could be relevant. Let's revisit it when we improve dfs2 functionality.
No description provided.