js8544 commented on issue #37322:
URL: https://github.com/apache/arrow/issues/37322#issuecomment-1689442942
Try this:
```python
schema = pa.schema(
[
pa.field("timestamp_col", pa.timestamp("ns", tz="UTC")),
pa.field("json_col", pa.struct([("can", pa.string())])),
pa.field("array_str_col", pa.list_(pa.string())),
pa.field("array_bigint_col", pa.list_(pa.int64())),
pa.field(
"array_json_col",
pa.list_(pa.struct([("foo", pa.string()), ("can",
pa.string())])),
),
]
)
table = pa.Table.from_pydict(
{
"timestamp_col": [datetime.now().timestamp()],
"json_col": [{"can": "haz"}],
"array_str_col": [["Flamingo", "Centipede"]],
"array_bigint_col": [np.arange(6, dtype=np.int64)],
"array_json_col": [[{"foo": "bar"}, {"can": "haz"}]],
},
schema=schema,
)
```
Two things I changed to make it work:
1. `datetime.now().isoformat()` returns a string but `pa.timestamp` expects
an int.
2. `pa.Table.from_pydict` expects the whole table, not a single row, so
you'll need to pass in a list for each column, not a single element.
--
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]