Skip to content

Commit dde1b30

Browse files
committed
Fix typing issues with load/store_chunk in Python
1 parent 2ea6412 commit dde1b30

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/binding/python/RecordComponent.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,14 @@ inline void store_chunk(
489489

490490
check_buffer_is_contiguous(a);
491491

492-
// dtype_from_numpy(a.dtype())
492+
if (!dtype_to_numpy(r.getDatatype()).is(a.dtype()))
493+
{
494+
std::stringstream err;
495+
err << "Attempting store from Python array of type '"
496+
<< dtype_from_numpy(a.dtype())
497+
<< "' into Record Component of type '" << r.getDatatype() << "'.";
498+
throw error::WrongAPIUsage(err.str());
499+
}
493500
switchDatasetType<StoreChunkFromPythonArray>(
494501
r.getDatatype(), r, a, offset, extent);
495502
}
@@ -770,6 +777,15 @@ inline void load_chunk(
770777

771778
check_buffer_is_contiguous(a);
772779

780+
if (!dtype_to_numpy(r.getDatatype()).is(a.dtype()))
781+
{
782+
std::stringstream err;
783+
err << "Attempting load into Python array of type '"
784+
<< dtype_from_numpy(a.dtype())
785+
<< "' from Record Component of type '" << r.getDatatype() << "'.";
786+
throw error::WrongAPIUsage(err.str());
787+
}
788+
773789
switchDatasetType<LoadChunkIntoPythonArray>(
774790
r.getDatatype(), r, a, offset, extent);
775791
}

test/python/unittest/API/APITest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,7 @@ def get_component_only():
24712471
iteration = series.snapshots()[0]
24722472
particles = iteration.particles["electrons"]
24732473

2474-
dset = io.Dataset(np.dtype("float"), [30])
2474+
dset = io.Dataset(np.dtype(np.float32), [30])
24752475
position_x = particles["position"]["x"]
24762476
position_x.reset_dataset(dset)
24772477
position_x[:] = np.arange(30, dtype=np.float32)

0 commit comments

Comments
 (0)