hgrecco / pint-pandas

Pandas support for pint
Other
172 stars 42 forks source link

Complex magnitudes and other non floats #146

Closed redhog closed 1 year ago

redhog commented 1 year ago

PintArray does not currently support magnitudes of any other type than float. This includes complex numbers, so storing e.g. complex frequencies or I/Q values is not possible. Other compound types have the same problem: I started experimenting with storing coordinates with associated CRS (epsg codes) as pint values which works fine (including reprojection in context converters), but they can't go in a PintArray either :(

MichaelTiemannOSC commented 1 year ago

Xref #139

redhog commented 1 year ago

Ah thanks, that's very similar.

https://github.com/MichaelTiemannOSC/pint-pandas/commit/b5954fdc78f8e8dd386ee77206e59af44c90489c#diff-3181ac97c806b62303f85f408bb9a556bdf5f61171d45ccc87df59a3c3adf6a5R228

would have to change. Why is the casting there at all? Can't self._data be a numpy array with dtype O if need be?

redhog commented 1 year ago

I also think you have to fix https://github.com/MichaelTiemannOSC/pint-pandas/commit/b5954fdc78f8e8dd386ee77206e59af44c90489c#diff-3181ac97c806b62303f85f408bb9a556bdf5f61171d45ccc87df59a3c3adf6a5R337

redhog commented 1 year ago

I'm not super familiar with the pint pandas code, but could give making a PR a try if you want, unless you can just whip that up super easily?

redhog commented 1 year ago

My projections implementation and example code:

https://github.com/emerald-geomodelling/experimental-pint/blob/master/pint%20projections.ipynb

MichaelTiemannOSC commented 1 year ago

@redhog I couldn't follow your comments into the diff, but I'm happy to make whatever changes. I've very new to the pint communities and have no pride of authorship (yet).

andrewgsavage commented 1 year ago

Ideally, for a solution that works for all types, we'd want

PRs that help tackle these issues are welcomed!

MichaelTiemannOSC commented 1 year ago

I second Andrew's encouragement to (1) solve the NA problems, so we are not stuck resorting to float NaNs to represent NA data, and (2) to avoid object dtype, not only because of speed/memory efficiency, but once something becomes and object_dtype, it loses all the wonderful properties of Extension Arrays.

redhog commented 1 year ago

Made a PR that solves this that I think works, but it might break some assumptions I'm not aware of...