Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect numpy types when creating tables #11

Closed
simonw opened this issue Feb 23, 2019 · 2 comments
Closed

Detect numpy types when creating tables #11

simonw opened this issue Feb 23, 2019 · 2 comments

Comments

@simonw
Copy link
Owner

simonw commented Feb 23, 2019

Inspired by #8

@simonw
Copy link
Owner Author

simonw commented Feb 23, 2019

Rough sketch:

+try:
+    import numpy
+except ImportError:
+    numpy = None
+
 Column = namedtuple(
     "Column", ("cid", "name", "type", "notnull", "default_value", "is_pk")
 )

@@ -70,6 +79,22 @@ class Database:
             datetime.time: "TEXT",
             None.__class__: "TEXT",
         }
+        # If numpy is available, add more types
+        if numpy:
+            col_type_mapping.update({
+                numpy.int8: "INTEGER",
+                numpy.int16: "INTEGER",
+                numpy.int32: "INTEGER",
+                numpy.int64: "INTEGER",
+                numpy.uint8: "INTEGER",
+                numpy.uint16: "INTEGER",
+                numpy.uint32: "INTEGER",
+                numpy.uint64: "INTEGER",
+                numpy.float16: "FLOAT",
+                numpy.float32: "FLOAT",
+                numpy.float64: "FLOAT",
+                numpy.float128: "FLOAT",
+            })

@simonw
Copy link
Owner Author

simonw commented Feb 23, 2019

Need to test this both with and without numpy installed.

simonw added a commit that referenced this issue Feb 24, 2019
@simonw simonw closed this as completed in e615d22 Feb 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant