sbu.parse_yaml

A module for parsing and validating the .yaml input.

Index

yaml_to_pandas(filename)

Create a Pandas DataFrame out of a .yaml file.

validate_usernames(df)

Validate that all users belonging to an account are available in the .yaml input file.

API

sbu.parse_yaml.yaml_to_pandas(filename)[source]

Create a Pandas DataFrame out of a .yaml file.

Examples

Example yaml input:

__project__: BlaBla
A:
    description: Example project
    PI: Walt Disney
    SBU requested: 1000
    users:
        user1: Donald Duck
        user2: Scrooge McDuck
        user3: Mickey Mouse

Example output:

>>> df, project = yaml_to_pandas(filename)

>>> print(df)
            info                  ...
         project            name  ... SBU requested           PI
username                          ...
user1          A     Donald Duck  ...        1000.0  Walt Disney
user2          A  Scrooge McDuck  ...        1000.0  Walt Disney
user3          A    Mickey Mouse  ...        1000.0  Walt Disney

>>> print(project)
BlaBla
Parameters

filename (str) – The path+filename to the .yaml file.

Returns

A Pandas DataFrame and project name constructed from filename. Columns and rows are instances of pandas.MultiIndex and pandas.Index, respectively. All retrieved .yaml data is stored under the "info" super-column. The project name will be None if the __project__ key is absent from the .yaml file

Return type

pandas.DataFrame & str, optional

sbu.parse_yaml.validate_usernames(df)[source]

Validate that all users belonging to an account are available in the .yaml input file.

Raises a KeyError If one or more usernames printed by the accinfo comand are absent from df.

Parameters

df (pandas.DataFrame) – A DataFrame, produced by yaml_to_pandas(), containing user accounts. pandas.DataFrame.columns and pandas.DataFrame.index should be instances of pandas.MultiIndex and pandas.Index, respectively. User accounts are expected to be stored in pandas.DataFrame.index.

Raises

ValueError – Raised if one or more users reported by the accinfo command are absent from df or vice versa.

Return type

None