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
Conversation
5c061f3
to
dc053d6
Compare
Ready to review/merge. |
So this is a refactor as opposed to a feature or bug fix? |
holoviews/core/dimension.py
Outdated
@@ -41,6 +41,41 @@ def param_aliases(d): | |||
return d | |||
|
|||
|
|||
def as_dimension(dimension): |
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.
Could this not simply be called dimension
?
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.
Nevermind...I see dimension
is frequently used as name even though dim
is a lot shorter.
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 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.
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.
How about asdim
?
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.
Can't say I prefer it but if you insist I'll do it.
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.
It is a lot shorter so I do prefer it..unless you have any specific objections to it?
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.
Okay, pushed.
It also fixes bugs when constructing Datasets with tuple dimensions. |
1754576
to
4128090
Compare
Looks good. I'll merge when the tests are green. |
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.