Support mapping from `np.int` and `np.float`
I have a NumPy array of values that I would like to put into Scylla. When I use np.ndarray.astype(SmallInt) it succeeds, but I get a marshalling error when I try to upload the data.
I am guessing that there is a lack of support for these types in scyllapy. I expect it to be a simple solution considering NumPy has Rust bindings.
Hi. I don't think that supporting such types is inside the scope of the driver. Here's an example of how you can insert numpy array in your database without any issue.
import asyncio
from scyllapy import Scylla
from scyllapy import extra_types
import numpy as np
async def main():
scylla = Scylla(
contact_points=["localhost"],
)
await scylla.startup()
await scylla.execute(
"CREATE KEYSPACE IF NOT EXISTS test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"
)
await scylla.execute(
"CREATE TABLE IF NOT EXISTS test.test (id int, data LIST<SMALLINT>, PRIMARY KEY (id));"
)
await scylla.execute("TRUNCATE test.test;")
arr = np.array(range(10), dtype=np.int8)
data = list(map(extra_types.SmallInt, arr)) # <-- Here's how you can convert numpy array to Scylla type
await scylla.execute("INSERT INTO test.test (id, data) VALUES (1, ?);", (data,))
res = await scylla.execute("SELECT * FROM test.test;")
print(res.all())
if __name__ == "__main__":
asyncio.run(main())
Yeah, that is what I do right now.
I think scope is purely defined by you; if you say it is within scope it would be. We wouldn't depend on numpy on the Python side, but on the rust side only. The type mapping would be in scope because you are mapping to types defined in this package.
Please reconsider.