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

ureg.year returns a Unit but ureg['year'] returns a Quantity. Why? #1303

Open
rjplevin opened this issue May 10, 2021 · 1 comment
Open

ureg.year returns a Unit but ureg['year'] returns a Quantity. Why? #1303

rjplevin opened this issue May 10, 2021 · 1 comment
Assignees
Milestone

Comments

@rjplevin
Copy link

ureg['year']
Out[18]: 1 <Unit('year')>
ureg.year
Out[19]: <Unit('year')>

This behavior seems to violate reasonable assumptions (and differs from the behavior of pandas, where df['colname'] is the same as df.colname, presuming colname is a valid identifier.)

If this is intentional, it's unclear why it makes sense for ureg['year'] to return a Quantity.

@jules-ch
Copy link
Collaborator

If you look at the code, this use case has been deprecated:

    def __getitem__(self, item):
        logger.warning(
            "Calling the getitem method from a UnitRegistry is deprecated. "
            "use `parse_expression` method or use the registry as a callable."
        )
        return self.parse_expression(item)

parse_expression returns a Quantity.

I agree with you on this, and since this deprecation is like 5 years old, we can safely do something about it.

So we can either remove this function or change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants