wireservice / csvkit

A suite of utilities for converting to and working with CSV, the king of tabular file formats.
https://csvkit.readthedocs.io
MIT License
6.03k stars 603 forks source link

TimeDeltas and json #1247

Closed wiluite closed 6 months ago

wiluite commented 6 months ago

Hello, Can TimeDeltas type objects be somehow json-serializable? (or is it expected to work, if not - no question)

csvstat some_timedelta.csv --json

TypeError: datetime.timedelta(seconds=60) is not JSON serializable

jpmckinney commented 6 months ago

Can you provide sample data? I have no idea how to reproduce.

wiluite commented 6 months ago

Any file with any TimeDelta.

file.csv

a,b
1 second,

csvstat -c 1 ./file.csv

  1. "a"

    Type of data:          TimeDelta
    Contains null values:  False
    Non-null values:       1
    Unique values:         1
    Smallest value:        0:00:01
    Largest value:         0:00:01
    Sum:                   0:00:01
    Mean:                  0:00:01
    Most common values:    0:00:01 (1x)

Row count: 1

csvstat -c 1 ./file.csv --json

TypeError: datetime.timedelta(seconds=1) is not JSON serializable
[{"column_id": 1, "column_name": "a", "type": "TimeDelta", "nulls": false, "nonnulls": 1, "unique": 1, "min":
jpmckinney commented 6 months ago

Aha, thanks!