Skip to content

Commit

Permalink
Add better verification of source df data
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitakuklev committed Mar 11, 2024
1 parent 096ef27 commit 247c007
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pysdds/readers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def read(filepath: Union[Path, str, IO[bytes]],
pages_mask = None

sdds = SDDSFile()
sdds.__source_file = str(filepath)
sdds._source_file = str(filepath)

logger.debug(f'Opening file "%s"', str(filepath))
#logger.debug(f'Mode (%s), compression (%s), endianness (%s)', mode, compression, endianness)
Expand Down
4 changes: 4 additions & 0 deletions pysdds/structures/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,13 +969,17 @@ def from_df(df_list: List[pd.DataFrame],
else:
val = df.iloc[:, i].values
sdds_type = constants._NUMPY_DTYPES_INV[df.dtypes.iloc[i]]
if sdds_type == object:
if not isinstance(val[0], str):
raise ValueError(f'Column [{c}] is of object type but items are not strings')
namelist = {'name': c, 'type': sdds_type}
col = Column(namelist, sdds)
sdds.columns.append(col)
col.data.append(val)

if parameter_dict is not None:
for i, (k, v) in enumerate(parameter_dict.items()):
assert isinstance(v, list), f'Data of parameter [{k}] is not a list'
assert len(v) == n_pages, f'Length {len(v)} of parameter {k} different from page ' \
f'count {n_pages}'
namelist = {'name': k, 'type': constants._PYTHON_TYPE_INV[type(v[0])]}
Expand Down

0 comments on commit 247c007

Please sign in to comment.