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

POC: Add the private/unused _array_dtypes function to test dtype conversions #3513

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

seisman
Copy link
Member

@seisman seisman commented Oct 14, 2024

Description of proposed changes

Inspired by the discussions in #3507 (comment), I think it's necessary to understand the string representation of different dtypes and what dtype they are converted to by NumPy. This PR adds a private _array_dtypes function to pygmt/clib/conversion.py. Please refer to the detailed docstrings for what the function does.

I think we should include the function in PyGMT although it's not used anywhere, similar to the array_to_datetime function which will no longer be used in PyGMT after #3507. I'm open to comments and more array-like objects should be added for testing.

@seisman
Copy link
Member Author

seisman commented Oct 14, 2024

The CI tests pass with Python 3.12 + pandas 2.2 but fail with Python 3.10 + panda 2.0:

[gw0] linux -- Python 3.10.15 /home/runner/micromamba/envs/pygmt/bin/python3.10
444     >>> _array_dtypes(np.datetime64("2021-01-01"))
445     ('datetime64[D]', 'datetime64[D]')
446 
447     For Pandas objects:
448 
449     >>> _array_dtypes(pd.Series(data=[1, 2, 3]))
450     ('int64', 'int64')
451     >>> _array_dtypes(pd.Series(data=[1.0, 2.0, 3.0]))
452     ('float64', 'float64')
453     >>> _array_dtypes(pd.Series(data=[1, 2, 3], dtype=pd.Int32Dtype()))
Expected:
    ('Int32', 'int32')
Got:
    ('Int32', 'object')

There are likely some changes between pandas 2.0 and 2.2 (or in NumPy). Anyway, it means we need to maintain the mapping from Int32 to int32 to support old versions and it also highlights the importance of this private function.

pygmt/clib/conversion.py Outdated Show resolved Hide resolved
pygmt/clib/conversion.py Outdated Show resolved Hide resolved
Co-authored-by: Michael Grund <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants