Skip to content

Commit 4f7de1d

Browse files
authored
Merge pull request #67 from ngoldbaum/static-pandas-stringdtype
Add a statically defined PandasStringDType
2 parents 99c94d7 + 958bd89 commit 4f7de1d

File tree

10 files changed

+443
-223
lines changed

10 files changed

+443
-223
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Install build and test dependencies
2020
run: |
2121
pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
22-
python -m pip install -U pip build pytest unyt wheel meson ninja meson-python patchelf
22+
python -m pip install -U pip build pytest unyt wheel meson ninja meson-python patchelf pandas
2323
- name: Install asciidtype
2424
working-directory: asciidtype
2525
run: |
@@ -78,3 +78,5 @@ jobs:
7878
working-directory: stringdtype
7979
run: |
8080
ASAN_OPTIONS=detect_leaks=false LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so pytest -s -vvv --color=yes
81+
pip uninstall -y pandas
82+
ASAN_OPTIONS=detect_leaks=false LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/11/libasan.so pytest -s -vvv --color=yes

stringdtype/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ build-backend = "mesonpy"
1111
[tool.black]
1212
line-length = 79
1313

14+
[tool.isort]
15+
profile = "black"
16+
line_length = 79
17+
1418
[project]
1519
name = "stringdtype"
1620
description = "A dtype for storing UTF-8 strings"

stringdtype/stringdtype/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@
33
"""
44

55
from .missing import NA # isort: skip
6-
from .scalar import StringScalar # isort: skip
6+
from .scalar import StringScalar, PandasStringScalar # isort: skip
77
from ._main import StringDType, _memory_usage
88

9+
try:
10+
from ._main import PandasStringDType
11+
except ImportError:
12+
PandasStringDType = None
13+
914
__all__ = [
1015
"NA",
1116
"StringDType",
1217
"StringScalar",
1318
"_memory_usage",
1419
]
20+
21+
# this happens when pandas isn't importable
22+
if PandasStringDType is None:
23+
del PandasStringDType
24+
else:
25+
__all__.extend("PandasStringDType")

stringdtype/stringdtype/scalar.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
"""A scalar type needed by the dtype machinery."""
1+
"""Scalar types needed by the dtype machinery."""
22

33

44
class StringScalar(str):
55
pass
6+
7+
8+
class PandasStringScalar(str):
9+
pass

stringdtype/stringdtype/src/casts.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,18 @@ static char *s2s_name = "cast_StringDType_to_StringDType";
8080

8181
static NPY_CASTING
8282
unicode_to_string_resolve_descriptors(PyObject *NPY_UNUSED(self),
83-
PyArray_DTypeMeta *NPY_UNUSED(dtypes[2]),
83+
PyArray_DTypeMeta *dtypes[2],
8484
PyArray_Descr *given_descrs[2],
8585
PyArray_Descr *loop_descrs[2],
8686
npy_intp *NPY_UNUSED(view_offset))
8787
{
8888
if (given_descrs[1] == NULL) {
89-
StringDTypeObject *new = new_stringdtype_instance(NA_OBJ);
89+
PyArray_Descr *new = (PyArray_Descr *)new_stringdtype_instance(
90+
(PyTypeObject *)dtypes[1]);
9091
if (new == NULL) {
9192
return (NPY_CASTING)-1;
9293
}
93-
loop_descrs[1] = (PyArray_Descr *)new;
94+
loop_descrs[1] = new;
9495
}
9596
else {
9697
Py_INCREF(given_descrs[1]);

0 commit comments

Comments
 (0)