hgrecco / pint-pandas

Pandas support for pint
Other
166 stars 41 forks source link

Support object magnitudes #148

Closed redhog closed 1 year ago

redhog commented 1 year ago
redhog commented 1 year ago

An example usage with objects as magnitudes to store geographic positions:

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

MichaelTiemannOSC commented 1 year ago

Nice! Based on my recent experiences with making a similar change to experiment with UFloats, I like it!

andrewgsavage commented 1 year ago

You need to test some non float dtypes that you'd like to support

andrewgsavage commented 1 year ago

To test other dtypes, do something like this in test_pandas_extensiontests.py


_all_numeric_dtypes = [float, int]

@pytest.fixture(params=_all_numeric_dtypes)
def data(request):
    return PintArray.from_1darray_quantity(np.arange(start=1.0, stop=101.0, dtype=request.param) * ureg.nm)

and change the rest of the fixtures to use the different dtypes too.

redhog commented 1 year ago

Will add tests and get back to you!

redhog commented 1 year ago

Realized I broke a bunch of tests. Have fixed all but one. Will fix that one too, then add the extra types as you requested.

andrewgsavage commented 1 year ago

there's a few tests that don't pass localy without my pandas forks. If you get the linting correct github will run the testsuite here

redhog commented 1 year ago

Tests now pass for complex128 dtype (and where that is not applicable, like divmod, are disabled for that dtype. @andrewgsavage Plase check if you think this is good enough for merging!

redhog commented 1 year ago

Btw, wrapped up the code that originally made me need this PR into a little library: https://github.com/redhog/print-proj It's so far a minimalistic/alpha version of a bridge between pint-pandas and geopandas...

andrewgsavage commented 1 year ago

I'm unsure how this will behave when mixing operations with floats and ints as that won't be tested in the pandas tests. Otherwise this looks good.

redhog commented 1 year ago

The tests fail in funny ways when some arrays are ints and others are floats (as opposed to all are one or the other)... Will have to look into how to make the tests behave tomorrow... But pretty sure the actual functionality is right, it's just the tests that are written assuming a simpler world...

redhog commented 1 year ago

I have now parametrized all test data to test for complex numbers. Note: No test tests for combining datasets with different dtypes. This is intentional; making that coerce nicely is outside of the scope of this PR in my opinion.

andrewgsavage commented 1 year ago

Yea that's fine. I'd like to get a version of pint-pandas released before merging this, then we can use this a bit to catch and fix those kind of issues.

@hgrecco could we get a pint-pandas 0.3 release?

redhog commented 1 year ago

Ping @andrewgsavage 0.3. is released, so... is this ready for merge then?

andrewgsavage commented 1 year ago

run pre-commit run --all-files to get linting working and add a note to changes

andrewgsavage commented 1 year ago

bors r+

bors[bot] commented 1 year ago

Build succeeded: