Skip to content

[Python] pyarrow can read integers as dates in list but not np.array #55315

Open

Description

@Kodiologist

Describe the bug, including details regarding any error messages, version, and platform.

>>> import pyarrow                                                            
>>> pyarrow.array([0, 1, 2], type = "date32")     
<pyarrow.lib.Date32Array object at 0x705c8e941f00>                                  
[            
  1970-01-01,
  1970-01-02,                                                                 
  1970-01-03                           
]                                                                             
>>> pyarrow.array(np.array([0, 1, 2]), type = "date32")                       
Traceback (most recent call last):                                            
  File "<python-input-4>", line 1, in <module>            
    pyarrow.array(np.array([0, 1, 2]), type = "date32")              
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^         
  File "pyarrow/array.pxi", line 414, in pyarrow.lib.array           
  File "pyarrow/array.pxi", line 97, in pyarrow.lib._ndarray_to_array         
    check_status(NdarrayToArrow(pool, values, mask, from_pandas,
  File "pyarrow/error.pxi", line 92, in pyarrow.lib.check_status              
pyarrow.lib.ArrowNotImplementedError: Unsupported cast from int64 to date32 using function cast_date32

I'm on pyarrow 26.0.0 and numpy 2.5.4.

Component(s)

Python

Activity

  1. changed the title [-]`pyarrow` can read integers as dates in `list` but not `np.array`[/-] [+][Python] `pyarrow` can read integers as dates in `list` but not `np.array`[/+] on Oct 29, 2026
  2. mohamd764 commented on Oct 29, 2026

    @mohamd764

    I can reproduce this on pyarrow 26.0.0 / numpy 2.5.4. The two inputs go through different paths: a Python list is converted value by value, so plain ints are accepted for date32, while a numpy array is wrapped as int64 first and then cast to the requested type. The date32 cast only has an int32 -> date32 kernel (GetDate32Cast in cpp/src/arrow/compute/kernels/scalar_cast_temporal.cc), so pa.array([0, 1, 2]).cast("date32") fails with the same error. date64 does have int64 -> date64, which is why that one works from numpy.

    Until that's added, either of these works with a numpy array:

    pa.array(np.array([0, 1, 2], dtype="int32"), type="date32")
    pa.array(np.array([0, 1, 2]).astype("datetime64[D]"))

    Both give 1970-01-01, 1970-01-02, 1970-01-03. An int64 -> date32 cast with an overflow check (the list path already raises "Integer too large for date32" for 2**40) would probably make the two paths consistent.

  3. Kodiologist commented on Oct 30, 2026

    @Kodiologist
    Author

    It looks like casting smaller integer types (like int16 and int8) to date32 also isn't supported.

  4. huong8373tt-beep commented on Nov 1, 2026

    @huong8373tt-beep

    I plan to investigate this issue and, if the source-level regression is confirmed, submit a focused fix with C++/Python regression coverage. I will first check for any existing work and validate the overflow behavior for integer-to-date32 casts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions