Skip to content

Commit

Permalink
Merge pull request #2 from AutoResearch/split-functions
Browse files Browse the repository at this point in the history
bug: convert np types to be storable in firebase
  • Loading branch information
younesStrittmatter authored May 27, 2023
2 parents 41244da + f03f1d4 commit 08612cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ requires-python = ">=3.8,<4"
dependencies = [
"autora-core",
"firebase-admin",
"numpy"
]

[project.optional-dependencies]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import time
from typing import Any
import numpy as np
import warnings

import firebase_admin
from firebase_admin import credentials, firestore
Expand Down Expand Up @@ -29,7 +31,16 @@ def _sequence_to_db_object(iterable):
"""
if not hasattr(iterable, "__iter__"):
return {0: iterable}
return {i: t for i, t in enumerate(iterable)}
is_int64 = False
is_float64 = False
for t in iterable:
is_int64 = is_int64 or isinstance(t, np.int64)
is_float64 = is_float64 or is_float64(t, np.float64)
if is_int64:
warnings.warn('Converting np.int64 to int to store in Firestore, may loose precision')
if is_float64:
warnings.warn('Converting np.float64 to float to store in Firestore, may loose precision')
return {i: int(t) if isinstance(t, np.integer) else float(t) if isinstance(t, np.floating) else t for i, t in enumerate(iterable)}


def _get_collection(
Expand Down

0 comments on commit 08612cc

Please sign in to comment.