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

Cleaned up Dimension casting and name lookup #2790

Merged
merged 5 commits into from Jun 26, 2018
Merged

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Jun 10, 2018

The code is currently littered with isinstance(dim, Dimension) checks, which is not optimal because it's duplicative but more importantly because it does not check for the full range of valid dimension specs which include tuples and dictionaries. This PR adds two utilities one to cast Dimension-like objects to Dimensions if it isn't already one and the other that looks up the name on Dimensions or Dimension-like objects. It then uses these utilities throughout the code.

  • Adds unit test

@philippjfr philippjfr added type: bug Something isn't correct or isn't working tag: component: data labels Jun 10, 2018
@philippjfr
Copy link
Member Author

Ready to review/merge.

@jlstevens
Copy link
Contributor

So this is a refactor as opposed to a feature or bug fix?

@@ -41,6 +41,41 @@ def param_aliases(d):
return d


def as_dimension(dimension):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this not simply be called dimension?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind...I see dimension is frequently used as name even though dim is a lot shorter.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I prefer as_dimension or asdimension, akin to numpy asarray, dimension is far too commonly used as a variable name so it would cause issues and be confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about asdim?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't say I prefer it but if you insist I'll do it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is a lot shorter so I do prefer it..unless you have any specific objections to it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, pushed.

@philippjfr
Copy link
Member Author

So this is a refactor as opposed to a feature or bug fix?

It also fixes bugs when constructing Datasets with tuple dimensions.

@jlstevens
Copy link
Contributor

Looks good. I'll merge when the tests are green.

@jlstevens jlstevens merged commit d6c0df0 into master Jun 26, 2018
@philippjfr philippjfr deleted the dimension_name_lookup branch July 4, 2018 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tag: component: data type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants