def test_destructors() -> None: def gen_values() -> Iterator[Dict[str, np.ndarray]]: yield {'x': np.arange(6)} yield {'y': np.arange(6)} t = Tafra(gen_values()) check_tafra(t) t = build_tafra() t = t.update_dtypes({'x': 'float'}) t.data['x'][2] = np.nan check_tafra(t) _ = tuple(t.to_records()) _ = tuple(t.to_records(columns='x')) _ = tuple(t.to_records(columns=['x'])) _ = tuple(t.to_records(columns=['x', 'y'])) _ = tuple(t.to_records(cast_null=False)) _ = tuple(t.to_records(columns='x', cast_null=False)) _ = tuple(t.to_records(columns=['x'], cast_null=False)) _ = tuple(t.to_records(columns=['x', 'y'], cast_null=False)) _ = t.to_list() _ = t.to_list(columns='x') _ = t.to_list(columns=['x']) _ = t.to_list(columns=['x', 'y']) _ = t.to_list(inner=True) _ = t.to_list(columns='x', inner=True) _ = t.to_list(columns=['x'], inner=True) _ = t.to_list(columns=['x', 'y'], inner=True) _ = t.to_tuple() _ = t.to_tuple(columns='x') _ = t.to_tuple(columns=['x']) _ = t.to_tuple(columns=['x', 'y']) _ = t.to_tuple(inner=True) _ = t.to_tuple(columns='x', inner=True) _ = t.to_tuple(columns=['x'], inner=True) _ = t.to_tuple(columns=['x', 'y'], inner=True) _ = t.to_array() _ = t.to_array(columns='x') _ = t.to_array(columns=['x']) _ = t.to_array(columns=['x', 'y']) _ = t.to_pandas() _ = t.to_pandas(columns='x') _ = t.to_pandas(columns=['x']) _ = t.to_pandas(columns=['x', 'y']) filepath = Path('test/test_to_csv.csv') t.to_csv(filepath) t.to_csv(filepath, columns='x') t.to_csv(filepath, columns=['x']) t.to_csv(filepath, columns=['x', 'y'])
def check_tafra(t: Tafra, check_rows: bool = True) -> bool: assert len(t._data) == len(t._dtypes) for c in t.columns: assert isinstance(t[c], np.ndarray) assert isinstance(t.data[c], np.ndarray) assert isinstance(t._data[c], np.ndarray) assert isinstance(t.dtypes[c], str) assert isinstance(t._dtypes[c], str) if check_rows: assert t._rows == len(t._data[c]) pd.Series(t._data[c]) columns = [c for c in t.columns][:-1] _ = t.to_records() _ = t.to_records(columns=columns) _ = t.to_list() _ = t.to_list(columns=columns) _ = t.to_list(inner=True) _ = t.to_list(columns=columns, inner=True) _ = t.to_tuple() _ = t.to_tuple(columns=columns) _ = t.to_tuple(name=None) _ = t.to_tuple(name='tf') _ = t.to_tuple(columns=columns, name=None) _ = t.to_tuple(columns=columns, name='tf') _ = t.to_tuple(inner=True) _ = t.to_tuple(inner=True, name=None) _ = t.to_tuple(inner=True, name='tf') _ = t.to_tuple(columns=columns, inner=True) _ = t.to_tuple(columns=columns, inner=True, name=None) _ = t.to_tuple(columns=columns, inner=True, name='tf') _ = t.to_array() _ = t.to_array(columns=columns) df = t.to_pandas() df = t.to_pandas(columns=columns) assert isinstance(df, pd.DataFrame) write_path = Path('test/test_to_csv.csv') t.to_csv(write_path) # t.to_csv(write_path, columns=columns) return True