Пример #1
0
def test_empty_read(_output_dir: str):
    df = MyTfs(plane="X", directory=_output_dir)
    write_tfs(df.get_filename(), df, save_index="NAME")
    df_read = MyTfs(plane="X", directory=_output_dir).read()
    assert_frame_equal(df, df_read,
                       check_exact=False)  # float precision can be an issue
    assert_dict_equal(df.headers, df_read.headers, compare_keys=True)
Пример #2
0
def remove_nan_from_files(list_of_files: list, replace: bool = False):
    """ Remove NAN-Entries from files in list_of_files.

    If replace=False a new file with .dropna in it's name is created, otherwise the file is
    overwritten.
    """
    for filepath in list_of_files:
        try:
            df = read_tfs(filepath)
            LOG.info(f"Read file {filepath:s}")
        except (IOError, TfsFormatError):
            LOG.info(f"Skipped file {filepath:s}")
        else:
            df = df.dropna(axis='index')
            if not replace:
                filepath += ".dropna"
            write_tfs(filepath, df)
Пример #3
0
def remove_nan_from_files(list_of_files: list, replace: bool = None) -> None:
    """ Remove NAN-Entries from files in list_of_files.

    If replace=False a new file with .dropna appended to its name is created, otherwise the file is
    overwritten.
    """
    replace = False if replace is None else replace
    for filepath in list_of_files:
        try:
            tfs_data_frame = read_tfs(filepath)
            LOG.info(f"Read file {filepath:s}")
        except (IOError, TfsFormatError):
            LOG.info(f"Skipped file {filepath:s}")
        else:
            tfs_data_frame = tfs_data_frame.dropna(axis="index")
            if not replace:
                filepath += ".dropna"
            write_tfs(filepath, tfs_data_frame)
Пример #4
0
 def write(self):
     self.validate_definitions()
     write_tfs(self._filename, self, save_index=self.index.name)
Пример #5
0
 def _write_tfs(self, filename, data_frame):
     if self.allow_write:
         write_tfs(os.path.join(self.directory, filename), data_frame)
     self._buffer[filename] = data_frame
Пример #6
0
def test_read_fail(_output_dir: str):
    mydf = MyTfs(plane="X", directory=_output_dir)
    df = TfsDataFrame(columns=["Does", "Not", "Exist"])
    write_tfs(mydf.get_filename(), df)
    with pytest.raises(KeyError):
        MyTfs(plane="X", directory=_output_dir).read()
Пример #7
0
def test_filled_read(_output_dir: str, _filled_tfs: MyTfs):
    df = _filled_tfs(plane="X", directory=_output_dir)
    write_tfs(df.get_filename(), df, save_index="NAME")
    df_read = MyTfs(plane="X", directory=_output_dir).read()
    assert_frame_equal(df, df_read)
    assert_dict_equal(df.headers, df_read.headers, compare_keys=True)
Пример #8
0
def test_filled_read(_output_dir, _filled_tfs):
    df = _filled_tfs(plane="X", directory=_output_dir)
    write_tfs(df.get_filename(), df, save_index="NAME")
    df_read = MyTfs(plane="X", directory=_output_dir).read()
    compare_dataframes(df, df_read)