Skip to content

Commit cfcd6c7

Browse files
committed
Allow h5py style dtypes to pass through
1 parent 05fc9a5 commit cfcd6c7

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/blosc2/blosc2_ext.pyx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,8 +2595,33 @@ cdef class NDArray:
25952595

25962596

25972597
cdef b2nd_context_t* create_b2nd_context(shape, chunks, blocks, dtype, kwargs):
2598-
# This is used only in constructors, dtype will always have NumPy format
2599-
dtype = np.dtype(dtype)
2598+
if isinstance(dtype, list) and len(dtype) > 0 and isinstance(dtype[0], tuple):
2599+
# Extract just the field names and basic dtype info
2600+
fields = []
2601+
for field in dtype:
2602+
name = field[0]
2603+
field_dtype = field[1]
2604+
2605+
# Handle different field formats:
2606+
# 1. ('name', ('|S10', {'h5py_encoding': 'ascii'})) - h5py style
2607+
# 2. ('name', '<i4') - standard NumPy style
2608+
# 3. ('name', '<i4', (shape,)) - NumPy with shape info
2609+
2610+
if isinstance(field_dtype, tuple) and len(field_dtype) > 0:
2611+
# h5py nested representation with metadata dict
2612+
field_dtype = field_dtype[0]
2613+
2614+
# Check if we have shape information as third element
2615+
if len(field) > 2 and field[2] is not None:
2616+
# Include the shape information
2617+
fields.append((name, field_dtype, field[2]))
2618+
else:
2619+
fields.append((name, field_dtype))
2620+
2621+
dtype = np.dtype(fields)
2622+
else:
2623+
dtype = np.dtype(dtype)
2624+
26002625
typesize = dtype.itemsize
26012626
if 'cparams' in kwargs:
26022627
kwargs['cparams']['typesize'] = typesize

0 commit comments

Comments
 (0)