Skip to content

Refactor index types#405

Draft
rabernat wants to merge 14 commits intopangeo-forge:beam-refactorfrom
rabernat:refactor-index-types
Draft

Refactor index types#405
rabernat wants to merge 14 commits intopangeo-forge:beam-refactorfrom
rabernat:refactor-index-types

Conversation

@rabernat
Copy link
Copy Markdown
Contributor

@rabernat rabernat commented Aug 29, 2022

This is an internal refactor of the core Index datatype. Like xarray-beam Key we use something that looks like a dictionary to keep track of where a fragment lies within a dataset.

This PR does a few things:

  • Moves Index to a standalone types module
  • Refactors Index to use a key value pair of Dimension and Position
  • Tries to eliminate redundancy in Position, moving closer to xarray-beam's "offests" concept.

We may be able to eventually just use the same type of index as xarray-beam. In the meantime, this simplifies things and moves us in that direction.

My main complaint is that this feels a very java-like.

cc @shoyer and @alxmrs if you want to take a look.

Copy link
Copy Markdown
Member

@alxmrs alxmrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small nits. Looks great!

]
if len(dims) != 1:
raise KeyError(r"Could not valid combine_dim for indexer {idx_key}")
raise KeyError(f"Could not valid combine_dim for dimension {dimension}")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal preference is {dimension!r}.

assert concat_dim_val.stop == concat_dim_val.start + dimsize
region_slice.append(slice(concat_dim_val.start, concat_dim_val.stop))
position = index[concat_dimension]
assert position.indexed
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be useful to have an assert message, maybe with some message to help end-users debug.

@rabernat rabernat mentioned this pull request Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants