verdict.py
def to_hdf5(
        self,
        filepath,
        attributes = None,
        overwrite_existing_file = True,
        condensed = False,
        handle_jagged_arrs = 'filled array',
        jagged_flag = 'jagged',
        sparse = False,
    ):
        '''Save the contents as a HDF5 file.

        Args:
            filepath (str):
                Location to save the hdf5 file at.

            attributes (dict):
                Dictionary of attributes to store as attributes for the HDF5
                file.

            overwrite_existing_file (boolean):
                If True and a file already exists at filepath, delete it prior
                to saving.

            condensed (boolean):
                If True, combine the innermost dictionaries into a condensed
                DataFrame/array-like format.

            handle_jagged_arrs (str):
                How to handle jagged arrays. Options:
                    filled array:
                        Create a uniform filled array capable of holding
                        any jagged arrays.
                    row datasets:
                        Save each row of a jagged array as a separate dataset.
                    assume_none:
                        Don't handle jagged arrays. Assume there are none.

            jagged_flag (str):
                Flag to indicate that this part of the hdf5 file contains part of
                an jagged array-like.

            sparse (boolean):
                If True use h5sparse instead of h5py, allowing saving of sparse matrices
                with reduced file size.
        '''

        # If using sparse matrices
        if sparse:
            hdf5_module = h5sparse
        else:
            hdf5_module = h5py

        # Make sure all contained dictionaries are verdict Dicts
        self = Dict( self )

        if overwrite_existing_file:
            if os.path.isfile( filepath ):
                os.remove( filepath )

        # Make sure the path exists
        os.makedirs(
            os.path.dirname( os.path.abspath( filepath ) ),
            exist_ok = True
        )

        with hdf5_module.File( filepath, 'w-' ) as f:

            # Store attributes
            if attributes is not None:
                for key, item in attributes.items():
                    f.attrs[key] = item

            def recursive_save( current_path, key, item ):
                '''Function for recursively saving to an hdf5 file.

                Args:
                    current_path (str):
                        Current location in the hdf5 file.

                    key (str):
                        Key to save.

                    item:
                        Item to save.
                '''

                # Update path
                current_path = '{}/{}'.format( current_path, key )

                # Convert missed dictionaries into verdict versions
                if isinstance( item, dict ):
                    item = Dict( item )

                if isinstance( item, Dict ):

                    # Make space for the data set
                    f.create_group( current_path )

                    # Save in condensed format
                    if condensed and item.depth() == 2:
                        df = item.to_df()

                        recursive_save(
                            current_path,
                            df.index.name,
                            df.index.values.astype( str )
                        )
                        for c_name in df.columns:
                            recursive_save(
                                current_path,
                                c_name,
                                df[c_name].values,
                            )

                    else:
                        # Recurse
                        for inner_key, inner_item in item.items():
                            recursive_save( current_path, inner_key, inner_item )

                # Save data if the inner item isn't a Dict
                else:

                    # Save a jagged array
                    if handle_jagged_arrs != 'assume_none':
                        if check_if_jagged_arr( item ):

                            create_dataset_jagged_arr(
                                f,
                                current_path,
                                item,
                                method = handle_jagged_arrs,
                                jagged_flag = jagged_flag,
                                hdf5_module = hdf5_module,
                            )
                        else:
                            create_dataset_fixed( f, current_path, item, hdf5_module=hdf5_module )
                    else:
                        create_dataset_fixed( f, current_path, item, hdf5_module=hdf5_module )

            # Shallow dictionary condensed edge case
            shallow_condensed_save = ( self.depth() <= 2 ) and condensed

            # Actual save
            if not shallow_condensed_save:
                for key, item in self.items():
                    recursive_save( '', key, item )

            # For relatively shallow dictionaries
            else:
                df = self.to_df()

                recursive_save(
                    '',
                    df.index.name,
                    df.index.values.astype( str )
                )
                for c_name in df.columns:
                    recursive_save(
                        '',
                        c_name,
                        df[c_name].values,
                    )
Save the contents as a HDF5 file.

        Args:
            filepath (str):
                Location to save the hdf5 file at.

            attributes (dict):
                Dictionary of attributes to store as attributes for the HDF5
                file.

            overwrite_existing_file (boolean):
                If True and a file already exists at filepath, delete it prior
                to saving.

            condensed (boolean):
                If True, combine the innermost dictionaries into a condensed
                DataFrame/array-like format.

            handle_jagged_arrs (str):
                How to handle jagged arrays. Options:
                    filled array:
                        Create a uniform filled array capable of holding
                        any jagged arrays.
                    row datasets:
                        Save each row of a jagged array as a separate dataset.
                    assume_none:
                        Don't handle jagged arrays. Assume there are none.

            jagged_flag (str):
                Flag to indicate that this part of the hdf5 file contains part of
                an jagged array-like.

            sparse (boolean):
                If True use h5sparse instead of h5py, allowing saving of sparse matrices
                with reduced file size.
        
Save the contents as a HDF5 file.
Save the contents as a HDF5 file .
def to_hdf5(
        self,
        filepath,
        attributes = None,
        overwrite_existing_file = True,
        condensed = False,
        handle_jagged_arrs = 'filled array',
        jagged_flag = 'jagged',
        sparse = False,
    ):
        if sparse:
            hdf5_module = h5sparse
        else:
            hdf5_module = h5py
        self = Dict( self )
        if overwrite_existing_file:
            if os.path.isfile( filepath ):
                os.remove( filepath )
        os.makedirs(
            os.path.dirname( os.path.abspath( filepath ) ),
            exist_ok = True
        )
        with hdf5_module.File( filepath, 'w-' ) as f:
            if attributes is not None:
                for key, item in attributes.items():
                    f.attrs[key] = item
            def recursive_save( current_path, key, item ):
                current_path = '{}/{}'.format( current_path, key )
                if isinstance( item, dict ):
                    item = Dict( item )
                if isinstance( item, Dict ):
                    f.create_group( current_path )
                    if condensed and item.depth() == 2:
                        df = item.to_df()
                        recursive_save(
                            current_path,
                            df.index.name,
                            df.index.values.astype( str )
                        )
                        for c_name in df.columns:
                            recursive_save(
                                current_path,
                                c_name,
                                df[c_name].values,
                            )
                    else:
                        for inner_key, inner_item in item.items():
                            recursive_save( current_path, inner_key, inner_item )
                else:
                    if handle_jagged_arrs != 'assume_none':
                        if check_if_jagged_arr( item ):
                            create_dataset_jagged_arr(
                                f,
                                current_path,
                                item,
                                method = handle_jagged_arrs,
                                jagged_flag = jagged_flag,
                                hdf5_module = hdf5_module,
                            )
                        else:
                            create_dataset_fixed( f, current_path, item, hdf5_module=hdf5_module )
                    else:
                        create_dataset_fixed( f, current_path, item, hdf5_module=hdf5_module )
            shallow_condensed_save = ( self.depth() <= 2 ) and condensed
            if not shallow_condensed_save:
                for key, item in self.items():
                    recursive_save( '', key, item )
            else:
                df = self.to_df()
                recursive_save(
                    '',
                    df.index.name,
                    df.index.values.astype( str )
                )
                for c_name in df.columns:
                    recursive_save(
                        '',
                        c_name,
                        df[c_name].values,
                    )
def to_hdf5 ( self , filepath , attributes = None , overwrite_existing_file = True , condensed = False , handle_jagged_arrs = 'filled array' , jagged_flag = 'jagged' , sparse = False , ) : if sparse : hdf5_module = h5sparse else : hdf5_module = h5py self = Dict ( self ) if overwrite_existing_file : if os . path . isfile ( filepath ) : os . remove ( filepath ) os . makedirs ( os . path . dirname ( os . path . abspath ( filepath ) ) , exist_ok = True ) with hdf5_module . File ( filepath , 'w-' ) as f : if attributes is not None : for key , item in attributes . items ( ) : f . attrs [ key ] = item def recursive_save ( current_path , key , item ) : '''Function for recursively saving to an hdf5 file.

                Args:
                    current_path (str):
                        Current location in the hdf5 file.

                    key (str):
                        Key to save.

                    item:
                        Item to save.
                ''' current_path = '{}/{}' . format ( current_path , key ) if isinstance ( item , dict ) : item = Dict ( item ) if isinstance ( item , Dict ) : f . create_group ( current_path ) if condensed and item . depth ( ) == 2 : df = item . to_df ( ) recursive_save ( current_path , df . index . name , df . index . values . astype ( str ) ) for c_name in df . columns : recursive_save ( current_path , c_name , df [ c_name ] . values , ) else : for inner_key , inner_item in item . items ( ) : recursive_save ( current_path , inner_key , inner_item ) else : if handle_jagged_arrs != 'assume_none' : if check_if_jagged_arr ( item ) : create_dataset_jagged_arr ( f , current_path , item , method = handle_jagged_arrs , jagged_flag = jagged_flag , hdf5_module = hdf5_module , ) else : create_dataset_fixed ( f , current_path , item , hdf5_module = hdf5_module ) else : create_dataset_fixed ( f , current_path , item , hdf5_module = hdf5_module ) shallow_condensed_save = ( self . depth ( ) <= 2 ) and condensed if not shallow_condensed_save : for key , item in self . items ( ) : recursive_save ( '' , key , item ) else : df = self . to_df ( ) recursive_save ( '' , df . index . name , df . index . values . astype ( str ) ) for c_name in df . columns : recursive_save ( '' , c_name , df [ c_name ] . values , )
Save the contents as a HDF5 file.
Save the contents as a HDF5 file .
'''Save the contents as a HDF5 file.

        Args:
            filepath (str):
                Location to save the hdf5 file at.

            attributes (dict):
                Dictionary of attributes to store as attributes for the HDF5
                file.

            overwrite_existing_file (boolean):
                If True and a file already exists at filepath, delete it prior
                to saving.

            condensed (boolean):
                If True, combine the innermost dictionaries into a condensed
                DataFrame/array-like format.

            handle_jagged_arrs (str):
                How to handle jagged arrays. Options:
                    filled array:
                        Create a uniform filled array capable of holding
                        any jagged arrays.
                    row datasets:
                        Save each row of a jagged array as a separate dataset.
                    assume_none:
                        Don't handle jagged arrays. Assume there are none.

            jagged_flag (str):
                Flag to indicate that this part of the hdf5 file contains part of
                an jagged array-like.

            sparse (boolean):
                If True use h5sparse instead of h5py, allowing saving of sparse matrices
                with reduced file size.
        ''' # If using sparse matrices # Make sure all contained dictionaries are verdict Dicts # Make sure the path exists # Store attributes '''Function for recursively saving to an hdf5 file.

                Args:
                    current_path (str):
                        Current location in the hdf5 file.

                    key (str):
                        Key to save.

                    item:
                        Item to save.
                ''' # Update path # Convert missed dictionaries into verdict versions # Make space for the data set # Save in condensed format # Recurse # Save data if the inner item isn't a Dict # Save a jagged array # Shallow dictionary condensed edge case # Actual save # For relatively shallow dictionaries
self
filepath
Location to save the hdf5 file at.
Location to save the hdf5 file at .
attributes
Dictionary of attributes to store as attributes for the HDF5
file.
Dictionary of attributes to store as attributes for the HDF5 file .
overwrite_existing_file
If True and a file already exists at filepath, delete it prior
to saving.
If True and a file already exists at filepath delete it prior to saving .
condensed
If True, combine the innermost dictionaries into a condensed
DataFrame/array-like format.
If True combine the innermost dictionaries into a condensed DataFrame / array - like format .
handle_jagged_arrs
None
jagged_flag
Flag to indicate that this part of the hdf5 file contains part of
an jagged array-like.
Flag to indicate that this part of the hdf5 file contains part of an jagged array - like .
sparse
If True use h5sparse instead of h5py, allowing saving of sparse matrices
with reduced file size.
If True use h5sparse instead of h5py allowing saving of sparse matrices with reduced file size .