Skip to content

Commit

Permalink
#180: make delete_existing and read_only mutually exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwoer committed Jul 19, 2024
1 parent 40c9434 commit 351cfd4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions alphabase/io/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,11 @@ def __init__(
Args:
file_name (str): file path.
read_only (bool, optional): If hdf is read-only. Defaults to True.
read_only (bool, optional): If hdf is read-only. Mutually exclusive with `delete_existing`. Defaults to True.
truncate (bool, optional): If existing groups and datasets can be
truncated (i.e. are overwitten). Defaults to False.
delete_existing (bool, optional): If the file already exists,
delete it completely and create a new one. Defaults to False.
delete it completely and create a new one. Mutually exclusive with `read_only`. Defaults to False.
Examples::
>>> # create a hdf file to write
Expand All @@ -486,7 +486,7 @@ def __init__(
>>> hdf_file.dfs.df1 = pd.DataFrame({'a':[1,2,3]})
>>> # write another DataFrame dataset into the dfs
>>> hdf_file.dfs.df2 = pd.DataFrame({'a':[3,2,1]})
>>> # set an property value to the dataframe
>>> # set a property value to the dataframe
>>> hdf_file.dfs.df1.data_from = "colleagues"
>>> # get a dataframe dataset from a dfs
>>> df1 = hdf_file.dfs.df1.values
Expand All @@ -498,6 +498,11 @@ def __init__(
>>> hdf_file.dfs.df1.data_from
"colleagues"
"""
if delete_existing and read_only:
raise ValueError(
"Parameters 'delete_existing' and 'read_only' are mutually exclusive."
)

if delete_existing:
mode = "w"
elif read_only:
Expand Down

0 comments on commit 351cfd4

Please sign in to comment.