Skip to content

Commit

Permalink
API: Update batch api parsing to handle date columns correctly (rtdip…
Browse files Browse the repository at this point in the history
…#822)

Signed-off-by: Ummer Taahir <[email protected]>
  • Loading branch information
ummer-shell authored Sep 2, 2024
1 parent 53f78a8 commit 4a46098
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/api/v1/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from datetime import datetime
import datetime as dt
import json
import os
import importlib.util
Expand Down Expand Up @@ -240,13 +241,15 @@ def get_as_dict(data):
def convert_value(x):
if isinstance(x, pd.Timestamp):
return x.isoformat(timespec="nanoseconds")
elif isinstance(x, dt.date):
return x.isoformat()
elif isinstance(x, pd.Timedelta):
return x.isoformat()
elif isinstance(x, Decimal):
return float(x)
return x

data_parsed = data.map(convert_value).replace({np.nan: None})
data_parsed = data.applymap(convert_value).replace({np.nan: None})
schema = build_table_schema(data_parsed, index=False, primary_key=False)
data_dict = data_parsed.to_dict(orient="records")

Expand Down

0 comments on commit 4a46098

Please sign in to comment.