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

Commit 3df7a67

Browse files
committed
implementation of get_all, get_any for dt64
1 parent a77f407 commit 3df7a67

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

arraymap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,15 @@ fam_get_any(FAMObject *self, PyObject *key) {
21322132
case NPY_STRING:
21332133
GET_ANY_FLEXIBLE(char, char_get_end_p, lookup_hash_string, string_to_hash);
21342134
break;
2135+
case NPY_DATETIME:
2136+
NPY_DATETIMEUNIT key_unit = dt_unit_from_array(key_array);
2137+
if (!kat_is_datetime_unit(self->keys_array_type, key_unit)) {
2138+
Py_DECREF(values);
2139+
return NULL;
2140+
}
2141+
GET_ANY_SCALARS(npy_int64, npy_int64, KAT_INT64, lookup_hash_int, int_to_hash,);
2142+
break;
2143+
21352144
}
21362145
}
21372146
else {

test/test_unit.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,28 @@ def test_fam_array_get_all_j():
857857
assert fam.get_all(np.array(("bb", "dd", "bb", "dd"))).tolist() == [1, 3, 1, 3]
858858

859859

860+
def test_fam_array_get_all_k1():
861+
a1 = np.array(("2023-01-05", "1854-05-02"), np.datetime64)
862+
a1.flags.writeable = False
863+
fam = FrozenAutoMap(a1)
864+
865+
post = fam.get_all(
866+
np.array(["1854-05-02", "2023-01-05", "2023-01-05"], np.datetime64)
867+
)
868+
assert post.tolist() == [1, 0, 0]
869+
870+
871+
def test_fam_array_get_all_k2():
872+
a1 = np.array(("2023-01-05", "1854-05-02"), np.datetime64)
873+
a1.flags.writeable = False
874+
fam = FrozenAutoMap(a1)
875+
876+
with pytest.raises(KeyError):
877+
post = fam.get_all(
878+
np.array(["1854-05-02", "2023-01-05", "2020-01-05"], np.datetime64)
879+
)
880+
881+
860882
# -------------------------------------------------------------------------------
861883

862884

@@ -901,3 +923,27 @@ def test_fam_array_get_any_b():
901923
assert post1 == list(fam.values())
902924
assert a1[0] in fam
903925
assert 4294967295 in fam
926+
927+
928+
def test_fam_array_get_any_c1():
929+
a1 = np.array(("2023-01-05", "1854-05-02"), np.datetime64)
930+
a1.flags.writeable = False
931+
fam = FrozenAutoMap(a1)
932+
933+
post = fam.get_any(
934+
np.array(
935+
["1854-05-02", "nat", "1854-05-02", "2023-01-05", "nat"], np.datetime64
936+
)
937+
)
938+
assert post == [1, 1, 0]
939+
940+
941+
def test_fam_array_get_any_c2():
942+
a1 = np.array(("2023-01-05", "1854-05-02"), np.datetime64)
943+
a1.flags.writeable = False
944+
fam = FrozenAutoMap(a1)
945+
946+
post = fam.get_any(
947+
np.array(["1854-05-02", "2023-01-05", "2020-01-05"], np.datetime64)
948+
)
949+
assert post == [1, 0]

0 commit comments

Comments
 (0)