-
Notifications
You must be signed in to change notification settings - Fork 12
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
implement the PintIndex
#163
Merged
Merged
Changes from 7 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
b9baa9c
add a `PintMetaIndex` that for now can only `sel`
keewis 89c5e2a
add a function to compare indexers
keewis 17e9aec
expect indexer dicts for strip_indexer_units
keewis 30a1d80
move the indexer comparison function to the utils
keewis 34caf09
change extract_indexer_units to expect a dict
keewis 05aa5a6
fix a few calls to extract_indexer_units
keewis 2e0e5bd
one more call
keewis 818db6c
Merge branch 'main' into pint-meta-index
keewis a049d03
implement `create_variables` and `from_variables`
keewis 0706bc6
use the new index to attach units to dimension coordinates
keewis a603860
pass the dictionary of indexers instead iterating manually
keewis dea881c
use `Coordinates._construct_direct`
keewis 9427b20
Merge branch 'main' into pint-meta-index
keewis a54b94a
delegate `isel` to the wrapped index and wrap the result
keewis 23d1f76
Merge branch 'main' into pint-meta-index
keewis f0d0890
add a inline `repr` for the index
keewis fa9f1b3
stubs for the remaining methods
keewis fb01e32
rename the index class to `PintIndex`
keewis 9278a2d
add a utility method to wrap the output of the wrapped index's methods
keewis 3200bc8
implement `equals`
keewis 281f03c
implement `roll`, `rename`, and `__getitem__` by forwarding
keewis c5e9022
start adding tests
keewis 2c2c814
add tests for `create_variables`
keewis e5d8369
add tests for `sel`
keewis 50a7287
add tests for `isel`
keewis 2b3c5bb
improve the tests for `sel`
keewis 57ea8e5
add tests for `equals`
keewis 3eed8c9
add tests for `roll`
keewis aebaf37
add tests for `rename`
keewis 58c540f
add tests for `__getitem__`
keewis 9cb7e91
add tests for `_repr_inline_`
keewis 9822520
configure coverage, just in case
keewis 55ccb00
use `_replace` instead of manually constructing the new index
keewis 6bd6726
explicitly check that the pint index gets created
keewis c7d523b
also verify that non-quantity variables don't become `PintIndex`ed
keewis bae3c3e
Merge branch 'main' into pint-meta-index
keewis 9dde67d
don't use `.pint.sel`
keewis 235ca0e
Merge branch 'main' into pint-meta-index
keewis b927436
fix `PintIndex.from_variables` and properly test it
keewis c31e6b0
quantify the test data
keewis 415d059
explicity quantify the input of the `interp_like` tests
keewis 1939b2d
also strip the units of `other`
keewis 2538104
change expectations in the conversion tests
keewis eb2c405
refactor `attach_units_dataset`
keewis 0d46b66
get `convert_units` to accept indexes
keewis caf4668
strip indexes as well
keewis 7303960
change the `.pint.to` tests to not include indexes
keewis e88738d
extract the units of `other` in `.pint.interp_like`
keewis 0b400d0
quantify the input and expected data in the `reindex` tests
keewis 5bd3ec7
remove the left-over explicit quantification in the `interp` tests
keewis 77eef6d
get `.pint.reindex` to work by explicitly converting, stripping, and …
keewis c38eb5a
quantify the input and expected objects in the `reindex_like` tests
keewis 7277eb5
get `reindex_like` to work with indexes
keewis c7cf340
quantify expected only if we expect to make use of it
keewis 948d20f
quantify input and expected objects in the `sel` and `loc` tests
keewis 8c76cbc
get `.pint.sel` and `.pint.loc` to work with the indexes
keewis f9cb15c
remove the warning about indexed coordinates
keewis 49942bf
preserve the order of the variables
keewis 20dd15c
remove the remaining uses of `Coordinates._construct_direct`
keewis 5efb318
whats-new entry
keewis f53539a
expose the index
keewis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from xarray.core.indexes import Index | ||
|
||
from . import conversion | ||
|
||
|
||
class PintMetaIndex(Index): | ||
# TODO: inherit from MetaIndex once that exists | ||
def __init__(self, *, index, units): | ||
"""create a unit-aware MetaIndex | ||
|
||
Parameters | ||
---------- | ||
index : xarray.Index | ||
The wrapped index object. | ||
units : mapping of hashable to unit-like | ||
The units of the indexed coordinates | ||
""" | ||
self.index = index | ||
self.units = units | ||
|
||
# don't need `from_variables`: we're always *wrapping* an existing index | ||
|
||
def sel(self, labels): | ||
converted_labels = conversion.convert_indexer_units(labels, self.units) | ||
stripped_labels = { | ||
name: conversion.strip_indexer_units(indexer) | ||
for name, indexer in converted_labels.items() | ||
} | ||
|
||
return self.index.sel(stripped_labels) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm actually I'm not sure how a
MetaIndex
class would look like. So far we used the generic term "meta-index" to refer to indexes that would wrap one or several indexes, but I don't know if there will be a need to provide a generic class for that.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 agree, it doesn't really look like we actually need a base class for that, but I noticed that a few methods don't make sense for meta-indexes,
from_variables
for example. It's probably fine to use the default for those, though.