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

unumpy.sin() and similar functions should behave with Pandas object like NumPy functions do #150

Open
lebigot opened this issue Feb 12, 2022 · 5 comments
Labels

Comments

@lebigot
Copy link
Collaborator

lebigot commented Feb 12, 2022

More specifically, numpy.sin() applied to a Pandas Series returns a Pandas Series, whereas unumpy.sin() returns a NumPy array.

See #133 (comment).

@MichaelTiemannOSC
Copy link

I'm looking to do two things:

  1. Use uncertainties as a Pandas ExtensionDtype (see https://stackoverflow.com/questions/68893521/simple-example-of-pandas-extensionarray)
  2. Use the new Pandas uncertainties ExtensionDtype in PintPandas do to unit-aware calculations with uncertainties (see Pint+Pandas+Uncertainties...how would you ... hgrecco/pint#1605)

Anybody else interested/able to help and/or guide? This is mostly new territory for me (but I have done big lifts in the past).

@MichaelTiemannOSC
Copy link

This is a nuisance that will have to be fixed: https://stackoverflow.com/questions/70908349/pandas-rolling-operation-on-categorical-column

@lebigot
Copy link
Collaborator Author

lebigot commented Oct 12, 2022

I'd be happy to punctually give a hand and brainstorm some; precisely, if you keep posting in the issues, I'll do my best to help.

I don't know how related this can be, but uncertainties could use a simpler interface with NumPy, and maybe this would help with Pandas as well? Some initial brainstorming can be found in #47.

@MichaelTiemannOSC
Copy link

MichaelTiemannOSC commented Oct 12, 2022

Wonderful! I just read through that history. Thus far, I've made very good progress by simply deleting from PintType (in Pint-Pandas) the code that forces conversion to float when casting via astype (see https://github.com/hgrecco/pint-pandas/blob/master/pint_pandas/pint_array.py#:~:text=if%20not%20np,copy%20%3D%20False).

I'm now confronting how code I wrote messes with Pint's assumption that it can read and understand what it writes. I think it's relatively common idiom (unless I'm an idiot) to create a quantity somewhere and then read that quantity back via the unit registry like so:

ureg(str(Q_(1, 'kt CO2e')))
# prints <Quantity(1, 'CO2e * kt')>

When the unit registry sees an uncertainty, it gets confused:

ureg(str(Q_(ufloat(1.0, 0.1), 'kt CO2e')))
*** pint.errors.DefinitionSyntaxError: missing unary operator "/"

But so much else works, except for needing to change my nan handling (unp.isnan). I'll report more as I get my code passing its first full run-trough of a test case.

@MichaelTiemannOSC
Copy link

Made some good progress, updated here: os-climate/ITR#159

Forks to Pint and Pandas mentioned in PR above and described at bottom of this thread: hgrecco/pint#1605

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

No branches or pull requests

2 participants