We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timestamp
I was wondering why the serialization of Pandas' Timestamp object was not possible even though they inherit from datetime.datetime.
datetime.datetime
>>> import orjson >>> orjson.__version__ '3.9.10' >>> import pandas as pd >>> import datetime dt = datetime.datetime(2023, 11, 23) >>> orjson.dumps(dt) b'"2023-11-23T00:00:00"' >>> ts = pd.Timestamp(dt) >>> isinstance(ts, datetime.datetime) True >>> orjson.dumps(ts) TypeError: Type is not JSON serializable: Timestamp
Wouldn't it better to check first if the object to serialize is a subclass of serializable types?
It already seems to be the case for classes inheriting from dict, but not from datetime.datetime.
dict
>>> class CustomDT(datetime.datetime): >>> pass >>> cdt = CustomDT(2023, 11, 23) >>> orjson.dumps(cdt) TypeError: Type is not JSON serializable: CustomDT >>> class CustomDict(dict): >>> pass >>> cdict = CustomDict([('key', 'value')]) >>> orjson.dumps(cdict) b'{"key":"value"}'
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I was wondering why the serialization of Pandas'
Timestamp
object was not possible even though they inherit fromdatetime.datetime
.Wouldn't it better to check first if the object to serialize is a subclass of serializable types?
It already seems to be the case for classes inheriting from
dict
, but not fromdatetime.datetime
.The text was updated successfully, but these errors were encountered: