-
-
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
Datasets more robust to non-string keys #2174
Changes from 3 commits
b4c7c87
fc3f729
e29273b
c15bcd0
b765c3c
e441614
4612ac0
b301b17
3edfda6
2ad7425
7052520
8f01942
186d3e3
8c75d1f
2656bea
e2241df
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ testpaths=xarray/tests | |
[flake8] | ||
max-line-length=79 | ||
ignore= | ||
W503 | ||
exclude= | ||
doc/ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -466,7 +466,17 @@ def _getitem_coord(self, key): | |
return self._replace_maybe_drop_dims(var, name=key) | ||
|
||
def __getitem__(self, key): | ||
if isinstance(key, basestring): | ||
try: | ||
is_coord_key = any([ | ||
isinstance(key, basestring), | ||
key in set(self.dims).union(self.coords) | ||
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. I would hesitate to do this fix -- it means Instead, I think the better option would be to avoid making use of 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. Yes, completely agree, thanks |
||
]) | ||
except TypeError: | ||
# not hashable, but testing with collections.Hashable is not | ||
# complete, since# tuples with slices inside will suggest | ||
# they're hashable | ||
is_coord_key = False | ||
if is_coord_key: | ||
return self._getitem_coord(key) | ||
else: | ||
# xarray-style array indexing | ||
|
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.
This is line break before operator, which has been changed in PEP8