Skip to content

Commit 255cfa5

Browse files
authored
Merge pull request #83 from ngoldbaum/release-mode
build in release mode by default; fix bugs revealed
2 parents ebbedec + 7bdbb45 commit 255cfa5

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ 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 pandas
22+
pip install --pre --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple pandas
23+
python -m pip install -U pip build pytest unyt wheel meson ninja meson-python patchelf
2324
- name: Install asciidtype
2425
working-directory: asciidtype
2526
run: |

stringdtype/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ per-file-ignores = {"__init__.py" = ["F401"]}
3535

3636
[tool.meson-python.args]
3737
dist = []
38-
setup = ["-Dbuildtype=debug"]
38+
setup = []
3939
compile = []
4040
install = []

stringdtype/stringdtype/src/casts.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ string_to_unicode(PyArrayMethod_Context *context, char *const data[],
388388
}
389389
else {
390390
this_string = (unsigned char *)(default_string.buf);
391+
n_bytes = default_string.len;
391392
}
392393
}
393394
else {

stringdtype/stringdtype/src/dtype.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ StringDType_richcompare(PyObject *self, PyObject *other, int op)
661661
StringDTypeObject *sself = (StringDTypeObject *)self;
662662
StringDTypeObject *sother = (StringDTypeObject *)other;
663663

664-
int eq;
664+
int eq = 0;
665665
PyObject *sna = sself->na_object;
666666
PyObject *ona = sother->na_object;
667667

@@ -706,6 +706,23 @@ StringDType_richcompare(PyObject *self, PyObject *other, int op)
706706
return ret;
707707
}
708708

709+
static Py_hash_t
710+
StringDType_hash(PyObject *self)
711+
{
712+
StringDTypeObject *sself = (StringDTypeObject *)self;
713+
PyObject *hash_tup = NULL;
714+
if (sself->na_object != NULL) {
715+
hash_tup = Py_BuildValue("(iO)", sself->coerce, sself->na_object);
716+
}
717+
else {
718+
hash_tup = Py_BuildValue("(i)", sself->coerce);
719+
}
720+
721+
Py_hash_t ret = PyObject_Hash(hash_tup);
722+
Py_DECREF(hash_tup);
723+
return ret;
724+
}
725+
709726
/*
710727
* This is the basic things that you need to create a Python Type/Class in C.
711728
* However, there is a slight difference here because we create a
@@ -724,6 +741,7 @@ StringDType_type StringDType = {
724741
.tp_methods = StringDType_methods,
725742
.tp_members = StringDType_members,
726743
.tp_richcompare = StringDType_richcompare,
744+
.tp_hash = StringDType_hash,
727745
}}},
728746
/* rest, filled in during DTypeMeta initialization */
729747
};

stringdtype/stringdtype/src/umath.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -871,17 +871,22 @@ init_ufunc(PyObject *numpy, const char *ufunc_name, PyArray_DTypeMeta **dtypes,
871871
.casting = casting,
872872
.flags = flags,
873873
.dtypes = dtypes,
874+
.slots = NULL,
874875
};
875876

877+
PyType_Slot resolve_slots[] = {
878+
{NPY_METH_resolve_descriptors, resolve_func},
879+
{NPY_METH_strided_loop, loop_func},
880+
{0, NULL}};
881+
882+
PyType_Slot strided_slots[] = {{NPY_METH_strided_loop, loop_func},
883+
{0, NULL}};
884+
876885
if (resolve_func == NULL) {
877-
PyType_Slot slots[] = {{NPY_METH_strided_loop, loop_func}, {0, NULL}};
878-
spec.slots = slots;
886+
spec.slots = strided_slots;
879887
}
880888
else {
881-
PyType_Slot slots[] = {{NPY_METH_resolve_descriptors, resolve_func},
882-
{NPY_METH_strided_loop, loop_func},
883-
{0, NULL}};
884-
spec.slots = slots;
889+
spec.slots = resolve_slots;
885890
}
886891

887892
if (PyUFunc_AddLoopFromSpec(ufunc, &spec) < 0) {

stringdtype/tests/test_stringdtype.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,24 @@ def dtype(na_object, coerce):
4949

5050

5151
def test_dtype_creation():
52+
hashes = set()
5253
dt = StringDType()
5354
assert not hasattr(dt, "na_object") and dt.coerce == 1
55+
hashes.add(hash(dt))
5456

5557
dt = StringDType(na_object=None)
5658
assert dt.na_object is None and dt.coerce == 1
59+
hashes.add(hash(dt))
5760

5861
dt = StringDType(coerce=False)
5962
assert not hasattr(dt, "na_object") and dt.coerce == 0
63+
hashes.add(hash(dt))
6064

6165
dt = StringDType(na_object=None, coerce=False)
6266
assert dt.na_object is None and dt.coerce == 0
67+
hashes.add(hash(dt))
68+
69+
assert len(hashes) == 4
6370

6471

6572
def test_scalar_creation():

0 commit comments

Comments
 (0)