Uploading pandas Data.Frame to scidbpy

Here are some ways to upload pandas Data.Frame to scidbpy

When data.frame contains integers and floats

You can upload as below:

import pandas as pd
from scidbpy import connect
db = connect()

# create a data.frame
df1 = pd.DataFrame({"A": [1, 2], "B": [1.35, 2.49]})

# upload to scidb
df1_arr = db.input('''<A: int64, B: float>[idx]''', upload_data=df1.to_records(index=False)).store()
df1_arr
# Array(DB('http://localhost:8080', None, None, None, False, None, False, 256, False), 'py_9240f3c85d3111ea8c4ba683e73c3509_1')
str(df1_arr) # to get the name of the array in scidb
# 'py_9240f3c85d3111ea8c4ba683e73c3509_1'

# Download back to python
db.iquery(query='''scan({0})'''.format(str(df1_arr)), fetch=True)
# .../scidbpy/schema.py:747: UserWarning: 2 type(s) promoted for null support. Precision loss may occur
#   self._promo_warning()
#    idx    A     B
# 0    0  1.0  1.35
# 1    1  2.0  2.49

When data.frame contains strings

If I try to upload as below, I see an instance crash.

import pandas as pd
from scidbpy import connect
db = connect()

df2 = pd.DataFrame({"A": ['x', 'y'], "B": [1.35, 2.49]})
df2_arr = db.input('''<A: string, B: float>[idx]''', upload_data=df1.to_records(index=False)).store()
# Error id: scidb::SCIDB_SE_NETWORK::SCIDB_LE_CANT_SEND_RECEIVE
# Error description: Network error. Cannot receive network message: Read failed: End of file (asio.misc:2).  An instance may be offline.. for url: http://localhost:8080/execute_query?query=project%28apply%28input%28%...

One solution is to specify not null in the array schema

df2_arr = db.input('''<A: string not null, B: float not null>[idx]''', upload_data=df2.to_records(index=False)).store()
str(df2_arr)
# py_5c627a585d3411eaa1d6a683e73c3509_1

# Download to scidb and confirm
db.iquery(query='''project({0}, A)'''.format(str(df2_arr)), fetch=True)
#    idx  A
# 0    0  x
# 1    1  y