Skip to content

Commit c2e6505

Browse files
committed
Support Pandas' new str type
1 parent e32ed3e commit c2e6505

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/duckdb_py/numpy/type.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ static NumpyNullableType ConvertNumpyTypeInternal(const string &col_type_str) {
5858
if (col_type_str == "string") {
5959
return NumpyNullableType::STRING;
6060
}
61+
if (col_type_str == "str") {
62+
return NumpyNullableType::STRING;
63+
}
6164
if (col_type_str == "object") {
6265
return NumpyNullableType::OBJECT;
6366
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pandas as pd
2+
import pytest
3+
from packaging.version import Version
4+
5+
import duckdb
6+
7+
8+
@pytest.mark.skipif(
9+
Version(pd.__version__) < Version("3.0"), reason="Pandas < 3.0 doesn't have the new string type yet"
10+
)
11+
def test_new_str_type_pandas_3_0():
12+
df = pd.DataFrame({"s": ["DuckDB"]}) # noqa: F841
13+
duckdb.sql("select * from df")
14+
15+
16+
@pytest.mark.skipif(Version(pd.__version__) >= Version("3.0"), reason="Pandas >= 3.0 has the new string type")
17+
def test_new_str_type_pandas_lt_3_0():
18+
pd.options.future.infer_string = True
19+
df = pd.DataFrame({"s": ["DuckDB"]}) # noqa: F841
20+
duckdb.sql("select * from df")

0 commit comments

Comments
 (0)