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 test_constructions() -> None: with pytest.raises(TypeError) as e: t = Tafra() # type: ignore # noqa with pytest.raises(ValueError) as e: t = Tafra({}) # type: ignore t = Tafra({'x': None}) check_tafra(t) t = Tafra({'x': Decimal('1.23456')}) check_tafra(t) t = Tafra({'x': np.array(1)}) check_tafra(t) t = Tafra({'x': np.array([1])}) check_tafra(t) t = Tafra({'x': [True, False]}) check_tafra(t) t = Tafra({'x': 'test'}) check_tafra(t) t.update_dtypes_inplace({'x': 'O'}) check_tafra(t) t = Tafra(enumerate(np.arange(6))) check_tafra(t) with pytest.raises(ValueError) as e: t = Tafra({'x': np.array([1, 2]), 'y': np.array([3., 4., 5.])}) 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_array() _ = t.to_array(columns='x') _ = t.to_array(columns=['x']) _ = t.to_array(columns=['x', 'y']) t = build_tafra() df = pd.DataFrame(t.data) _ = Tafra.from_series(df['x']) check_tafra(_) _ = Tafra.from_dataframe(df) check_tafra(_) _ = Tafra.as_tafra(df) check_tafra(_) _ = Tafra.as_tafra(df['x']) check_tafra(_) _ = Tafra.as_tafra(t) check_tafra(_) _ = Tafra.as_tafra({'x': np.array(1)}) check_tafra(_) _ = Tafra.from_series(Series()) check_tafra(_) _ = Tafra.as_tafra(Series()) check_tafra(_) _ = Tafra.from_dataframe(DataFrame()) # type: ignore check_tafra(_) _ = Tafra.as_tafra(DataFrame()) check_tafra(_) with pytest.raises(TypeError) as e: _ = Tafra(np.arange(6)) with pytest.raises(TypeError) as e: _ = Tafra.as_tafra(np.arange(6))