pd.Timedelta is not JSON serializable
See original GitHub issueIn:
td = pd.timedelta_range(0,periods=3,freq='h')
alt.Chart(
pd.DataFrame(dict(id=np.arange(td.size),timedelta = td))
).mark_bar(
).encode(
x = 'timedelta',
y ='id:O'
)
Out:
~/anaconda/anaconda/envs/rr_dev/lib/python3.5/json/encoder.py in default(self, o)
177
178 """
--> 179 raise TypeError(repr(o) + " is not JSON serializable")
180
181 def encode(self, o):
TypeError: Timedelta('0 days 00:00:00') is not JSON serializable
In:
print ('pandas',pd.__version__)
print ('altair',alt.__version__)
Out:
pandas 0.23.0
altair 2.1.0
Expected, but I’m not sure that is achievable without timeUnit="hoursminutes"
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
How to overcome "datetime.datetime not JSON serializable"?
Every time JSON tries to convert a value it does not know how to convert it will call the function we passed to...
Read more >TypeError: Object of type datetime is not JSON serializable
The Python "TypeError: Object of type datetime is not JSON serializable" occurs when we try to convert a datetime object to a JSON...
Read more >Object of type datetime is not JSON serializable - CodeProject
Solution 2. Generally, using of json. dumps with a custom converter. By default, it converts everything it doesn't know to a string.
Read more >How to serialize a datetime object as JSON using Python?
TypeError: datetime.datetime (...) is not JSON serializable. How can we fix this? In the first example we can see the problem:.
Read more >Tableau and Python
... is not JSON serializable. the script is attached below: SCRIPT_REAL(". import quants_core. import numpy as np. import pandas as pd. from datetime...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK, I’ve added a better error in #974
For future reference, I ended up with a workaround like this:
If Altair/Vega supported timedeltas out of the box, this could be reduced to
(the helper function is not strictly needed in this reduced example, but in my actual usecase this is part of a more complex operation with some filtering and grouping before and after)