Skip to content

Commit

Permalink
feat: support 8bit ints (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorwoods committed Mar 25, 2024
1 parent ee30092 commit e2ec7f5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions newsfragments/280.feat
@@ -0,0 +1,3 @@
Adds support for writing DataFrames/Tables that have 8 bit integers. Hyper does
not have an 8 bit integer data type, so it will be converted to a 16 bit integer
upon writing.
2 changes: 2 additions & 0 deletions src/pantab/writer.cpp
Expand Up @@ -18,6 +18,7 @@ static auto GetHyperTypeFromArrowSchema(struct ArrowSchema *schema,
}

switch (schema_view.type) {
case NANOARROW_TYPE_INT8:
case NANOARROW_TYPE_INT16:
return hyperapi::SqlType::smallInt();
case NANOARROW_TYPE_INT32:
Expand Down Expand Up @@ -356,6 +357,7 @@ static auto MakeInsertHelper(std::shared_ptr<hyperapi::Inserter> inserter,
}

switch (schema_view.type) {
case NANOARROW_TYPE_INT8:
case NANOARROW_TYPE_INT16:
return std::make_unique<IntegralInsertHelper<int16_t>>(
inserter, chunk, schema, error, column_position);
Expand Down
19 changes: 19 additions & 0 deletions tests/test_writer.py
Expand Up @@ -348,3 +348,22 @@ def test_write_date_bug(tmp_hyper):
[tab_api.Date(2024, 1, 1)],
[tab_api.Date(2024, 1, 31)],
]


def test_eight_bit_int(tmp_hyper):
frame = pd.DataFrame(list(range(10)), columns=["nums"]).astype("int8")

pt.frame_to_hyper(frame, tmp_hyper, table="test")

with tab_api.HyperProcess(
tab_api.Telemetry.DO_NOT_SEND_USAGE_DATA_TO_TABLEAU
) as hyper:
with tab_api.Connection(
hyper.endpoint, tmp_hyper, tab_api.CreateMode.CREATE_IF_NOT_EXISTS
) as connection:
table_def = connection.catalog.get_table_definition(
tab_api.TableName("test")
)
num_col = table_def.get_column_by_name("nums")
assert num_col is not None
assert num_col.type == tab_api.SqlType.small_int()

0 comments on commit e2ec7f5

Please sign in to comment.