aosingh opened a new pull request, #502:
URL: https://github.com/apache/arrow-nanoarrow/pull/502

   Addresses https://github.com/apache/arrow-nanoarrow/issues/478
   
   Currently, if you create a `c_array` from an iterable of timestamps an error 
is raised
   
   Code:
   ```python
   from datetime import datetime
   
   import nanoarrow as na
   import pyarrow as pa
   
   
   def gen_timestamp():
       for i in range(100):
           yield int(round(datetime.now().timestamp()))
   
   timestamp_array = na.c_array(gen_timestamp(), na.timestamp("s"))
   
   parray = pa.Table.from_arrays([timestamp_array], names=["timestamp"])
   
   print(parray.to_pandas())
   ```
   Error:
   ```
   Traceback (most recent call last):
     File 
"/Users/as/nanoarrow_poc/.venv/lib/python3.12/site-packages/nanoarrow/c_array.py",
 line 128, in c_array
       builder = builder_cls(schema)
                 ^^^^^^^^^^^^^^^^^^^
     File 
"/Users/as/nanoarrow_poc/.venv/lib/python3.12/site-packages/nanoarrow/c_array.py",
 line 457, in __init__
       raise ValueError(
   ValueError: Can't build array of type timestamp from iterable
   ```
   
   Expected output:
   ```
                timestamp
   0  2024-05-31 18:43:10
   1  2024-05-31 18:43:10
   2  2024-05-31 18:43:10
   3  2024-05-31 18:43:10
   4  2024-05-31 18:43:10
   ..                 ...
   95 2024-05-31 18:43:10
   96 2024-05-31 18:43:10
   97 2024-05-31 18:43:10
   98 2024-05-31 18:43:10
   99 2024-05-31 18:43:10
   
   [100 rows x 1 columns]
   ```
   
   Benefits
   - Pyarrow Table and Pandas Dataframe can use the corresponding nanoarrow 
Array Type to cast the values when using `to_pandas`
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to