revert to dataframe.to_json
This commit is contained in:
parent
f677dea6a4
commit
97a6fb285f
@ -10,7 +10,6 @@ from typing import Any, Dict, Iterator, List, Mapping, Union
|
|||||||
from typing.io import IO
|
from typing.io import IO
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import orjson
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import rapidjson
|
import rapidjson
|
||||||
|
|
||||||
@ -263,15 +262,7 @@ def dataframe_to_json(dataframe: pd.DataFrame) -> str:
|
|||||||
:param dataframe: A pandas DataFrame
|
:param dataframe: A pandas DataFrame
|
||||||
:returns: A JSON string of the pandas DataFrame
|
:returns: A JSON string of the pandas DataFrame
|
||||||
"""
|
"""
|
||||||
# https://github.com/pandas-dev/pandas/issues/24889
|
return dataframe.to_json(orient='split')
|
||||||
# https://github.com/pandas-dev/pandas/issues/40443
|
|
||||||
# We need to convert to a dict to avoid mem leak
|
|
||||||
def default(z):
|
|
||||||
if isinstance(z, pd.Timestamp):
|
|
||||||
return z.timestamp() * 1e3
|
|
||||||
raise TypeError
|
|
||||||
|
|
||||||
return str(orjson.dumps(dataframe.to_dict(orient='split'), default=default), 'utf-8')
|
|
||||||
|
|
||||||
|
|
||||||
def json_to_dataframe(data: str) -> pd.DataFrame:
|
def json_to_dataframe(data: str) -> pd.DataFrame:
|
||||||
|
Loading…
Reference in New Issue
Block a user