Skip to content

clib.conversion._to_numpy: Add tests for pyarrow.array with date32/date64 dtype #3609

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

Merged
merged 3 commits into from
Nov 14, 2024

Conversation

seisman
Copy link
Member

@seisman seisman commented Nov 10, 2024

Description of proposed changes

Add tests for pyarrow.array with date64/date32 dtype.

These two types can be converted directly to numpy datetime64 with correct date units, as shown below.

In [1]: from datetime import datetime, date

In [2]: import numpy as np

In [3]: import pyarrow as pa

In [4]: x = pa.array([datetime(2012, 1, 1), date(2013, 1, 1)], type=pa.date32())

In [5]: x
Out[5]:
<pyarrow.lib.Date32Array object at 0x7f7142b70c40>
[
  2012-01-01,
  2013-01-01
]

In [6]: np.ascontiguousarray(x)
Out[6]: array(['2012-01-01', '2013-01-01'], dtype='datetime64[D]')

In [7]: x = pa.array([datetime(2012, 1, 1), date(2013, 1, 1)], type=pa.date64())

In [8]: x
Out[8]:
<pyarrow.lib.Date64Array object at 0x7f726ffb8ca0>
[
  2012-01-01,
  2013-01-01
]

In [9]: np.ascontiguousarray(x)
Out[9]:
array(['2012-01-01T00:00:00.000', '2013-01-01T00:00:00.000'],
      dtype='datetime64[ms]')

@seisman seisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog needs review This PR has higher priority and needs review. labels Nov 10, 2024
@seisman seisman added this to the 0.14.0 milestone Nov 10, 2024
@seisman seisman force-pushed the to_numpy/pyarrow_date32_date64 branch from 0174a49 to 795796d Compare November 10, 2024 14:12
@weiji14 weiji14 changed the title clib.conversion._to_numpy: Add tests for pyarrow.array with date32/da64 dtype clib.conversion._to_numpy: Add tests for pyarrow.array with date32/date64 dtype Nov 11, 2024
@michaelgrund michaelgrund added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Nov 12, 2024
@seisman seisman requested a review from weiji14 November 14, 2024 04:08
@seisman seisman merged commit 66b22dc into main Nov 14, 2024
17 of 18 checks passed
@seisman seisman deleted the to_numpy/pyarrow_date32_date64 branch November 14, 2024 04:27
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants