-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow for consistenty ordered coords #4755
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
Conversation
Would this be a smaller change overall (aside from typing)? |
I think slightly smaller, yes. |
As discussed in dev meeting:
|
@max-sixty see #4744 |
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 forgot to submit these suggestions before the meeting, so they might be out-of-date (but possibly still helpful).
def _names(self) -> Set[Hashable]: | ||
return set(self._data._coords) | ||
def _names(self) -> List[Hashable]: | ||
return list(sorted(self._data._coords)) |
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.
sorted
always returns a list
:
return list(sorted(self._data._coords)) | |
return sorted(self._data._coords) |
new_coord_names = coord_names + [x for x in vars_to_replace if x not in coord_names] | ||
new_coord_names = [x for x in new_coord_names if x not in vars_to_remove] |
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.
not sure if we can come up with something more efficient (or if being efficient is really necessary), but this seems a bit wasteful (we iterate over set(vars_to_replace) - set(coord_names)
twice). Maybe something like this:
new_coord_names = coord_names + [x for x in vars_to_replace if x not in coord_names] | |
new_coord_names = [x for x in new_coord_names if x not in vars_to_remove] | |
new_coord_names = [x for x in coord_names if x not in vars_to_remove] | |
new_coord_names += [ | |
x | |
for x in vars_to_replace | |
if x not in coord_names and x not in vars_to_remove | |
] |
?
new_coord_names = coord_names + [x for x in vars_to_create if x not in coord_names] | ||
new_coord_names = [x for x in new_coord_names if x not in vars_to_remove] |
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.
same here:
new_coord_names = coord_names + [x for x in vars_to_create if x not in coord_names] | |
new_coord_names = [x for x in new_coord_names if x not in vars_to_remove] | |
new_coord_names = [x for x in coord_names if x not in vars_to_remove] | |
new_coord_names += [ | |
x | |
for x in vars_to_create | |
if x not in coord_names and x not in vars_to_remove | |
] |
@@ -690,7 +691,8 @@ def __init__( | |||
self._file_obj = None | |||
self._encoding = None | |||
self._variables = variables | |||
self._coord_names = coord_names | |||
# TODO: can we remove `sorted` and let it be user-defined? | |||
self._coord_names = sorted(coord_names) |
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'm not sure if user-defined is a good idea for Dataset
, see #4649. sorted
would have the advantage of always being predictable.
Going to close this in favor of using an |
isort . && black . && mypy . && flake8
whats-new.rst
api.rst
I took an initial stab at allowing for consistently ordered coords, which came up recently, by using a list rather than a set. It's fairly involved, and the currently proposed code fails quite a few tests.
Another option would be to use
OrderedSet
. Or to leave it as aset
.