Skip to content

Commit 1a02e67

Browse files
committed
handle type casting with NaN values
1 parent 8401693 commit 1a02e67

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

gnss_lib_py/navdata/navdata.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,19 @@ def pandas_df(self):
614614

615615
df_list = []
616616
for row in self.rows:
617-
df_list.append(np.atleast_1d(
617+
dtype = self.orig_dtypes[row]
618+
if np.issubdtype(dtype, np.integer):
619+
row_data = self[row]
620+
row_data = row_data.astype(np.float64)
621+
if np.any(np.isnan(row_data)):
622+
nan_indexes = np.isnan(row_data)
623+
row_data[~nan_indexes] = row_data[~nan_indexes].astype(dtype)
624+
df_list.append(np.atleast_1d(row_data))
625+
else:
626+
df_list.append(np.atleast_1d(
627+
self[row].astype(self.orig_dtypes[row])))
628+
else:
629+
df_list.append(np.atleast_1d(
618630
self[row].astype(self.orig_dtypes[row])))
619631

620632
# transpose list to conform to Pandas input
@@ -739,7 +751,16 @@ def __getitem__(self, key_idx):
739751

740752
if isinstance(rows,list) and len(rows) == 1 \
741753
and self.inv_map[rows[0]] in self.orig_dtypes:
742-
arr_slice = arr_slice.astype(self.orig_dtypes[self.inv_map[rows[0]]])
754+
dtype = self.orig_dtypes[self.inv_map[rows[0]]]
755+
if np.issubdtype(dtype, np.integer):
756+
arr_slice = arr_slice.astype(np.float64)
757+
if np.any(np.isnan(arr_slice)):
758+
nan_indexes = np.isnan(arr_slice)
759+
arr_slice[~nan_indexes] = arr_slice[~nan_indexes].astype(dtype)
760+
else:
761+
arr_slice = arr_slice.astype(dtype)
762+
else:
763+
arr_slice = arr_slice.astype(dtype)
743764

744765
# remove all dimensions of length one
745766
arr_slice = np.squeeze(arr_slice)

0 commit comments

Comments
 (0)