diff --git a/tests/pandas_ts/conftest.py b/tests/pandas_ts/conftest.py index b29b248..e69de29 100644 --- a/tests/pandas_ts/conftest.py +++ b/tests/pandas_ts/conftest.py @@ -1,15 +0,0 @@ -from numpy.testing import assert_array_equal - - -def assert_nested_array_series_equal(a, b): - assert_array_equal(a.index, b.index) - for inner_a, inner_b in zip(a, b): - assert_array_equal(inner_a, inner_b, err_msg=f"Series '{a.name}' is not equal series '{b.name}'") - - -def assert_df_equal(a, b): - assert_array_equal(a.index, b.index) - assert_array_equal(a.columns, b.columns) - assert_array_equal(a.dtypes, b.dtypes) - for column in a.columns: - assert_array_equal(a[column], b[column], err_msg=f"Column '{column}' is not equal column '{column}'") diff --git a/tests/pandas_ts/test_packer.py b/tests/pandas_ts/test_packer.py index 5345f85..b7369b4 100644 --- a/tests/pandas_ts/test_packer.py +++ b/tests/pandas_ts/test_packer.py @@ -1,8 +1,8 @@ import numpy as np import pandas as pd import pyarrow as pa -from conftest import assert_nested_array_series_equal from numpy.testing import assert_array_equal +from pandas.testing import assert_frame_equal, assert_series_equal from pandas_ts import packer @@ -54,13 +54,7 @@ def test_pack_df(): }, ) - assert_array_equal(actual.index, desired.index) - assert_array_equal(actual.dtypes, desired.dtypes) - assert_array_equal(actual.columns, desired.columns) - assert actual.shape == desired.shape - - for column in actual.columns: - assert_nested_array_series_equal(actual[column], desired[column]) + assert_frame_equal(actual, desired) def test_pack_df_into_structs(): @@ -86,8 +80,7 @@ def test_pack_df_into_structs(): ), ) - assert actual.dtype == desired.dtype - assert_nested_array_series_equal(actual, desired) + assert_series_equal(actual, desired) def test_pack_sorted_df_into_struct(): @@ -113,8 +106,7 @@ def test_pack_sorted_df_into_struct(): ), ) - assert actual.dtype == desired.dtype - assert_nested_array_series_equal(actual, desired) + assert_series_equal(actual, desired) def test_view_packed_df_as_struct_series(): @@ -139,7 +131,7 @@ def test_view_packed_df_as_struct_series(): series = packer.view_packed_df_as_struct_series(packed_df) for field_name in packed_df.columns: - assert_nested_array_series_equal(series.struct.field(field_name), packed_df[field_name]) + assert_series_equal(series.struct.field(field_name), packed_df[field_name]) def test_view_sorted_df_as_nested_arrays(): @@ -172,8 +164,7 @@ def test_view_sorted_df_as_nested_arrays(): index=[1, 2, 3, 4], dtype=pd.ArrowDtype(pa.list_(pa.int64())), ) - for column in nested_df: - assert_nested_array_series_equal(nested_df[column], desired_nested[column]) + assert_frame_equal(nested_df, desired_nested) assert_array_equal(nested_df.attrs["_offset"], [0, 2, 4, 6, 9]) assert_array_equal(nested_df.attrs["_offset"], nested_df["a"].attrs["_offset"]) @@ -199,7 +190,7 @@ def test_view_sorted_series_as_nested_array(): index=[1, 2, 3, 4], dtype=pd.ArrowDtype(pa.list_(pa.int64())), ) - assert_nested_array_series_equal(nested, desired_nested) + assert_series_equal(nested, desired_nested) assert_array_equal(nested.attrs["_offset"], [0, 2, 4, 6, 9]) diff --git a/tests/pandas_ts/test_ts_accessor.py b/tests/pandas_ts/test_ts_accessor.py index cc5abf6..3e5bb00 100644 --- a/tests/pandas_ts/test_ts_accessor.py +++ b/tests/pandas_ts/test_ts_accessor.py @@ -6,8 +6,8 @@ import pandas as pd import pyarrow as pa import pytest -from conftest import assert_df_equal, assert_nested_array_series_equal from numpy.testing import assert_array_equal +from pandas.testing import assert_frame_equal, assert_series_equal @pytest.mark.skip("It is really tricky to test it: some other test may import pandas-ts before this one") @@ -95,12 +95,7 @@ def test_ts_accessor_to_nested(): ), }, ) - - assert_array_equal(nested.dtypes, desired.dtypes) - assert_array_equal(nested.index, desired.index) - - for column in nested.columns: - assert_nested_array_series_equal(nested[column], desired[column]) + assert_frame_equal(nested, desired) def test_ts_accessor_to_flat(): @@ -168,20 +163,22 @@ def test_ts_accessor___getitem__(): ) series = pd.Series(struct_array, dtype=pd.ArrowDtype(struct_array.type), index=[0, 1]) - assert_nested_array_series_equal( + assert_series_equal( series.ts["a"], pd.Series( [np.array([1.0, 2.0, 3.0]), np.array([1.0, 2.0, 1.0])], dtype=pd.ArrowDtype(pa.list_(pa.float64())), index=[0, 1], + name="a", ), ) - assert_nested_array_series_equal( + assert_series_equal( series.ts["b"], pd.Series( [-np.array([4.0, 5.0, 6.0]), -np.array([3.0, 4.0, 5.0])], dtype=pd.ArrowDtype(pa.list_(pa.float64())), index=[0, 1], + name="b", ), ) @@ -199,7 +196,7 @@ def test_ts_accessor_get(): series = pd.Series(struct_array, dtype=pd.ArrowDtype(struct_array.type), index=[100, 101]) second_row_as_df = series.ts.get(101) - assert_df_equal( + assert_frame_equal( second_row_as_df, pd.DataFrame({"a": np.array([1.0, 2.0, 1.0]), "b": -np.array([3.0, 4.0, 5.0])}) ) @@ -218,6 +215,6 @@ def test_ts_accessor_iget(): series = pd.Series(struct_array, dtype=pd.ArrowDtype(struct_array.type), index=[100, 101]) first_row_as_df = series.ts.iget(-2) - assert_df_equal( + assert_frame_equal( first_row_as_df, pd.DataFrame({"a": np.array([1.0, 2.0, 3.0]), "b": -np.array([4.0, 5.0, 6.0])}) )