Example #1
0
    def update(self, area_name: str, update_values: Dict[rules.ColumnNames,
                                                         str]):
        """
        Change a value in the database.
        """
        # Get index for area_name
        index_for_area = self.columns[rules.ColumnNames.AREA.value].index(
            area_name)

        # Iterate over keys in update_values dict
        for key in update_values:

            # Get the current values
            column_values = self.columns[key.value]

            # Update value at index
            column_values[index_for_area] = update_values[key]

            # Make copy of instance dataframe
            database = self.database.copy()

            # Update column in dataframe with updated value
            database[key.value] = column_values

            # Validate
            database = rules.database_schema().validate(database)

            # Set new database
            self.database = database

            # Reset columns cached property
            self._columns = None
Example #2
0
def read_database_csv(path: Path) -> pd.DataFrame:
    """
    Read database csv.
    """
    csv = pd.read_csv(path, index_col=0, sep=rules.DATABASE_CSV_SEP, dtype=str)
    assert isinstance(csv, pd.DataFrame)
    csv = rules.database_schema().validate(csv)
    return csv
Example #3
0
def test_read_database_csv(database_csv):
    """
    Test read_database_csv.
    """
    path = database_csv
    database_csv = repo.read_database_csv(path=path)
    validated = rules.database_schema().validate(database_csv)
    assert isinstance(validated, pd.DataFrame)
Example #4
0
 def __post_init__(self):
     """
     Post initialization steps.
     """
     assert self.tracerepository_path.exists()
     self.database = rules.database_schema().validate(self.database)
     self.unorganized_folder = (self.tracerepository_path /
                                rules.PathNames.UNORGANIZED.value)
Example #5
0
def write_database_csv(path: Path, database: pd.DataFrame):
    """
    Write database.csv to disk.
    """
    database = rules.database_schema().validate(database)
    database.to_csv(
        path_or_buf=path,
        sep=rules.DATABASE_CSV_SEP,
        index=True,
        index_label=rules.ColumnNames.AREA.value,
    )
Example #6
0
def scaffold(tracerepository_path: Path) -> pd.DataFrame:
    """
    Make scaffold start for a repo.
    """
    unorganized_path = tracerepository_path / rules.PathNames.UNORGANIZED.value
    data_path = tracerepository_path / rules.PathNames.DATA.value
    # Make unorganized folder
    unorganized_path.mkdir(exist_ok=True)
    data_path.mkdir(exist_ok=True)

    # # Make other default folders

    # for path in rules.folder_structure():
    #     path.mkdir(exist_ok=True, parents=True)

    # Create dataframe for relations between datasets
    df = scaffold_database()
    assert df is not None

    # Validate dataframe with pandera
    df = rules.database_schema().validate(df)
    return df