Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit e64dc1a

Browse files
committed
additional tests
1 parent 2448e48 commit e64dc1a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

arraymap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,7 @@ fam_get_all(FAMObject *self, PyObject *key) {
19761976
case NPY_DATETIME: {
19771977
NPY_DATETIMEUNIT key_unit = dt_unit_from_array(key_array);
19781978
if (!kat_is_datetime_unit(self->keys_array_type, key_unit)) {
1979+
PyErr_SetString(PyExc_KeyError, "datetime64 units do not match");
19791980
Py_DECREF(array);
19801981
return NULL;
19811982
}
@@ -2159,8 +2160,7 @@ fam_get_any(FAMObject *self, PyObject *key) {
21592160
case NPY_DATETIME:
21602161
NPY_DATETIMEUNIT key_unit = dt_unit_from_array(key_array);
21612162
if (!kat_is_datetime_unit(self->keys_array_type, key_unit)) {
2162-
Py_DECREF(values);
2163-
return NULL;
2163+
return values;
21642164
}
21652165
GET_ANY_SCALARS(npy_int64, npy_int64, KAT_INT64, lookup_hash_int, int_to_hash,);
21662166
break;

test/test_unit.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,14 @@ def test_fam_array_get_all_k2():
879879
)
880880

881881

882+
def test_fam_array_get_all_l():
883+
a1 = np.array(("2023-01-05", "1854-05-02", "1988-01-01"), np.datetime64)
884+
a1.flags.writeable = False
885+
fam = FrozenAutoMap(a1)
886+
with pytest.raises(KeyError):
887+
_ = fam.get_all(np.array(["2022-01", "2023-01", "1988-01"], np.datetime64))
888+
889+
882890
# -------------------------------------------------------------------------------
883891

884892

@@ -947,3 +955,12 @@ def test_fam_array_get_any_c2():
947955
np.array(["1854-05-02", "2023-01-05", "2020-01-05"], np.datetime64)
948956
)
949957
assert post == [1, 0]
958+
959+
960+
def test_fam_array_get_any_d():
961+
a1 = np.array(("2023-01-05", "1854-05-02", "1988-01-01"), np.datetime64)
962+
a1.flags.writeable = False
963+
fam = FrozenAutoMap(a1)
964+
965+
post = fam.get_any(np.array(["2022-01", "2023-01", "1988-01"], np.datetime64))
966+
assert post == []

0 commit comments

Comments
 (0)