Skip to content

Commit 5472db8

Browse files
committed
Handle byte types in reult_type calculation
1 parent ea71102 commit 5472db8

2 files changed

Lines changed: 7 additions & 19 deletions

File tree

examples/ndarray/string_arrays.ipynb

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 3,
14+
"execution_count": 1,
1515
"metadata": {},
1616
"outputs": [
1717
{
@@ -42,7 +42,7 @@
4242
},
4343
{
4444
"cell_type": "code",
45-
"execution_count": 4,
45+
"execution_count": 2,
4646
"metadata": {},
4747
"outputs": [
4848
{
@@ -52,7 +52,7 @@
5252
" dtype='|S12')"
5353
]
5454
},
55-
"execution_count": 4,
55+
"execution_count": 2,
5656
"metadata": {},
5757
"output_type": "execute_result"
5858
}
@@ -83,7 +83,7 @@
8383
},
8484
{
8585
"cell_type": "code",
86-
"execution_count": 6,
86+
"execution_count": 3,
8787
"metadata": {},
8888
"outputs": [
8989
{
@@ -125,21 +125,9 @@
125125
},
126126
{
127127
"cell_type": "code",
128-
"execution_count": 11,
128+
"execution_count": 4,
129129
"metadata": {},
130-
"outputs": [
131-
{
132-
"ename": "AttributeError",
133-
"evalue": "module 'blosc2' has no attribute 'lower'",
134-
"output_type": "error",
135-
"traceback": [
136-
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
137-
"\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)",
138-
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[11]\u001b[39m\u001b[32m, line 26\u001b[39m\n\u001b[32m 22\u001b[39m np.testing.assert_array_equal((a1_blosc >= a2_blosc)[:], a1 >= a2)\n\u001b[32m 23\u001b[39m np.testing.assert_array_equal((a1_blosc > a2_blosc)[:], a1 > a2)\n\u001b[32m 25\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m func, npfunc \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(\n\u001b[32m---> \u001b[39m\u001b[32m26\u001b[39m (\u001b[43mblosc2\u001b[49m\u001b[43m.\u001b[49m\u001b[43mlower\u001b[49m, blosc2.upper), (np.char.lower, np.char.upper), strict=\u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[32m 27\u001b[39m ):\n\u001b[32m 28\u001b[39m expr_lazy = func(a1_blosc)\n\u001b[32m 29\u001b[39m res_numexpr = npfunc(a1)\n",
139-
"\u001b[31mAttributeError\u001b[39m: module 'blosc2' has no attribute 'lower'"
140-
]
141-
}
142-
],
130+
"outputs": [],
143131
"source": [
144132
"for t in (\"bytes\", \"string\"):\n",
145133
" if t == \"bytes\":\n",

src/blosc2/lazyexpr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2822,7 +2822,7 @@ def result_type(
28222822
# Follow NumPy rules for scalar-array operations
28232823
# Create small arrays with the same dtypes and let NumPy's type promotion determine the result type
28242824
arrs = [
2825-
(np.array(value).dtype if isinstance(value, str) else value)
2825+
(np.array(value).dtype if isinstance(value, (str, bytes)) else value)
28262826
if (np.isscalar(value) or not hasattr(value, "dtype"))
28272827
else np.array([0], dtype=_convert_dtype(value.dtype))
28282828
for value in arrays_and_dtypes

0 commit comments

Comments
 (0)