From a817669674c351a3b4ea26221270cc0bef2983fa Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 4 Oct 2023 10:04:27 -0700 Subject: [PATCH] Remove casting-related warning --- .../data_reader/io_reader/utilities.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/utilities.py b/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/utilities.py index 5b729102..7e2d8e07 100644 --- a/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/utilities.py +++ b/openpmd_viewer/openpmd_timeseries/data_reader/io_reader/utilities.py @@ -63,7 +63,14 @@ def get_data(series, record_component, i_slice=None, pos_slice=None, if pos_slice is None: # mask invalid regions with NaN # note: full_like triggers a full read, thus we avoid it #340 - data = np.full(record_component.shape, np.nan, record_component.dtype) + # (only for floating-point types) + if np.issubdtype(data.dtype, np.floating) or \ + np.issubdtype(data.dtype, np.complexfloating): + data = np.full(record_component.shape, np.nan, record_component.dtype) + else: + # Other types do not support NaN + data = np.full(record_component.shape, 0, record_component.dtype) + for chunk in chunks: chunk_slice = chunk_to_slice(chunk) @@ -90,7 +97,13 @@ def get_data(series, record_component, i_slice=None, pos_slice=None, del slice_shape[dir_index] # mask invalid regions with NaN - data = np.full(slice_shape, np.nan, dtype=record_component.dtype) + # (only for floating-point types) + if np.issubdtype(data.dtype, np.floating) or \ + np.issubdtype(data.dtype, np.complexfloating): + data = np.full(slice_shape, np.nan, dtype=record_component.dtype) + else: + # Other types do not support NaN + data = np.full(slice_shape, 0, dtype=record_component.dtype) # build requested ND slice with respect to full data s = []