alphabase.io.hdf

Classes:

HDF_Dataframe(*, file_name, name[, ...])

HDF_Dataset(*, file_name, name[, read_only, ...])

HDF_File(file_name, *[, read_only, ...])

HDF_Group(*, file_name, name[, read_only, ...])

HDF_Object(*, file_name, name[, read_only, ...])

A generic class to access HDF components.

class alphabase.io.hdf.HDF_Dataframe(*, file_name: str, name: str, read_only: bool = True, truncate: bool = False)[source][source]

Bases: HDF_Group

Methods:

append(data)

set_slice(slice_selection, df)

Attributes:

append(data)[source][source]
property columns
property dtype
set_slice(slice_selection, df)[source][source]
property values
class alphabase.io.hdf.HDF_Dataset(*, file_name: str, name: str, read_only: bool = True, truncate: bool = False)[source][source]

Bases: HDF_Object

Methods:

__init__(*, file_name, name[, read_only, ...])

append(data)

create_mmap()

delete_mmap()

set_slice(slice_selection, values)

Attributes:

__init__(*, file_name: str, name: str, read_only: bool = True, truncate: bool = False)[source][source]
append(data)[source][source]
create_mmap()[source][source]
delete_mmap()[source][source]
property dtype
property mmap
set_slice(slice_selection, values)[source][source]
property shape
property values
class alphabase.io.hdf.HDF_File(file_name: str, *, read_only: bool = True, truncate: bool = False, delete_existing: bool = False)[source][source]

Bases: HDF_Group

Methods:

__init__(file_name, *[, read_only, ...])

HDF file object to load/save the hdf file.

__init__(file_name: str, *, read_only: bool = True, truncate: bool = False, delete_existing: bool = False)[source][source]

HDF file object to load/save the hdf file. It also provides convenient attribute-like accesses to operate the data in the HDF object.

Instead of relying directly on the h5py interface, we will use an HDF wrapper file to provide consistent access to only those specific HDF features we want. Since components of an HDF file come in three shapes datasets, groups and attributes, we will first define a generic HDF wrapper object to handle these components. Once this is done, the HDF wrapper file can be treated as such an object with additional features to open and close the initial connection.

Parameters:
  • file_name (str) – file path.

  • read_only (bool, optional) – If hdf is read-only. Mutually exclusive with delete_existing and truncate. Defaults to True.

  • truncate (bool, optional) – If existing groups and datasets can be truncated (i.e. are overwitten). Mutually exclusive with read_only. Defaults to False.

  • delete_existing (bool, optional) – If the file already exists, delete it completely and create a new one. Mutually exclusive with read_only. Defaults to False.

Examples::
>>> # create a hdf file to write
>>> hdf_file = HDF_File(hdf_file_path, read_only=False, truncate=True, delete_existing=True)
>>> # create an empty group as "dfs"
>>> hdf_file.dfs = {}
>>> # write a DataFrame dataset into the dfs
>>> 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 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
>>> # features below are not important, but may be useful sometimes
>>> # get the dataframe via the dataset name instead of attribute
>>> df1 = hdf_file.dfs.__getattribute__("df1").values
>>> # get the dataframe via the dataset path (i.e. "dfs/df1")
>>> df1 = hdf_file.__getattribute__('dfs').__getattribute__("df1").values
>>> hdf_file.dfs.df1.data_from
"colleagues"
class alphabase.io.hdf.HDF_Group(*, file_name: str, name: str, read_only: bool = True, truncate: bool = False)[source][source]

Bases: HDF_Object

Methods:

__init__(*, file_name, name[, read_only, ...])

add_dataset(name, array)

add_group(name, group)

set_read_only([read_only])

set_truncate([truncate])

Attributes:

__init__(*, file_name: str, name: str, read_only: bool = True, truncate: bool = False)[source][source]
add_dataset(name: str, array: ndarray)[source][source]
add_group(name: str, group: dict)[source][source]
property components
property dataframe_names
property dataframes
property dataset_names
property datasets
property group_names
property groups
set_read_only(read_only: bool = True)[source][source]
set_truncate(truncate: bool = True)[source][source]
class alphabase.io.hdf.HDF_Object(*, file_name: str, name: str, read_only: bool = True, truncate: bool = False)[source][source]

Bases: object

A generic class to access HDF components.

Methods:

__init__(*, file_name, name[, read_only, ...])

editing_mode([read_only, truncate])

set_read_only([read_only])

set_truncate([truncate])

Attributes:

__init__(*, file_name: str, name: str, read_only: bool = True, truncate: bool = False)[source][source]
editing_mode(read_only: bool = False, truncate: bool = True)[source]
property file_name
property metadata
property name
property read_only
set_read_only(read_only: bool = True)[source][source]
set_truncate(truncate: bool = True)[source][source]
property truncate