Skip to content
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

New properties Dataset.sizes and DataArray.sizes #1076

Merged
merged 1 commit into from
Nov 4, 2016
Merged

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Nov 3, 2016

This allows for consistent access to dimension lengths on Dataset and
DataArray

xref #921 (doesn't resolve it 100%, but should help significantly)

numpy.squeeze
"""
if dim is None:
dim = [d for d, s in self.sizes.item() if s == 1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think items?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops indeed

@@ -110,6 +111,31 @@ def __setitem__(self, key, value):
self.data_array[pos_indexers] = value


class DataArraySizes(collections.Mapping, formatting.ReprMixin):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need a separate class that holds the array?
Could it be a dict of dim-name to dim-size?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not -- could just generate an object on the fly, e.g., Frozen(OrderedDict(zip(self.dims, self.shape))). Let me do a quick micro benchmark to see if that has appreciably different performance.

This allows for consistent access to dimension lengths on ``Dataset`` and
``DataArray``

xref pydata#921 (doesn't resolve it 100%, but should help significantly)
@shoyer
Copy link
Member Author

shoyer commented Nov 3, 2016

Updated to remove the custom class. It makes accessing a single dimension length from DataArray.sizes slightly slower, but within the range of usual Python overhead (2.5 vs. 5 us). Could add a cache at some later point if necessary.

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