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

Commit 5fe8678

Browse files
authored
Merge pull request #9 from static-frame/8/null-bytes
2 parents d09db25 + 1cf7d4d commit 5fe8678

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ ArrayMap requires the following:
3636
What is New in ArrayMap
3737
-------------------------
3838

39+
0.1.5
40+
........
41+
42+
Improved handling for Unicode elements that contain non-terminal NULL strings.
43+
44+
3945
0.1.4
4046
........
4147

arraymap.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,14 @@ typedef enum ViewKind{
124124

125125
// NOTE: would like to use strchr(str, '\0') instead of this routine, but some buffers might not have a null terminator and stread by full to the the dt_size.
126126
static inline Py_UCS4*
127-
ucs4_get_end_p(Py_UCS4* p, Py_ssize_t dt_size) {
128-
Py_UCS4* p_end = p + dt_size;
129-
while (p < p_end && *p != '\0') {
130-
p++;
127+
ucs4_get_end_p(Py_UCS4* p_start, Py_ssize_t dt_size) {
128+
Py_UCS4* p;
129+
for (p = p_start + dt_size - 1; p >= p_start; p--) {
130+
if (*p != '\0') {
131+
return p + 1; // return 1 more than the first non-null from the right
132+
}
131133
}
132-
return p;
134+
return p; // p is equal to p_start
133135
}
134136

135137

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55

66

7-
AM_VERSION = "0.1.4"
7+
AM_VERSION = "0.1.5"
88

99

1010
with open("README.rst") as file:

test/test_property.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ def strategy(contiguous: bool):
5252
shape=1, unique=True, fill=st.nothing(), dtype=scalar_dtypes()
5353
).map(partial(proc, contiguous=contiguous))
5454

55-
return st.one_of(strategy(contiguous=True), strategy(contiguous=False))
55+
return st.one_of(
56+
strategy(contiguous=True),
57+
strategy(contiguous=False),
58+
)
5659

5760

5861
@given(keys=hypothesis.infer)

test/test_unit.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ def test_fam_constructor_array_int_d():
9292
assert k in fam
9393

9494

95-
# def test_fam_constructor_array_a3():
96-
# a1 = np.array(("a", "bb", "ccc"))
97-
# with pytest.raises(TypeError):
98-
# fam = FrozenAutoMap(a1)
99-
10095
# ------------------------------------------------------------------------------
10196

10297

@@ -142,6 +137,38 @@ def test_fam_constructor_array_unicode_c():
142137
fam = FrozenAutoMap(a1)
143138

144139

140+
# NOTE
141+
# >>> u = "\x000\x00"
142+
# >>> len(u)
143+
# 3
144+
# >>> a1 = np.array(['', ''], dtype='U4')
145+
# >>> a1[0] = u
146+
# >>> a1
147+
# array(['\x000', ''], dtype='<U4')
148+
# >>> len(a1[0])
149+
# 2
150+
151+
152+
def test_fam_constructor_array_unicode_d1():
153+
a1 = np.array(["", "\x000"], dtype="U2")
154+
a1.flags.writeable = False
155+
fam = FrozenAutoMap(a1)
156+
assert len(fam) == 2
157+
assert list(fam) == ["", "\x000"]
158+
assert "" in fam
159+
assert "\x000" in fam
160+
161+
162+
def test_fam_constructor_array_unicode_d2():
163+
a1 = np.array(["", "\x000\x00"], dtype="U3")
164+
a1.flags.writeable = False
165+
fam = FrozenAutoMap(a1)
166+
assert len(fam) == 2
167+
assert list(fam) == ["", "\x000"] # we lost the last null
168+
assert "" in fam
169+
assert "\x000" in fam
170+
171+
145172
def test_fam_copy_array_unicode_a():
146173
a1 = np.array(("a", "ccc", "bb"))
147174
a1.flags.writeable = False

0 commit comments

Comments
 (0)