Skip to content

Commit 594c587

Browse files
committed
add column multi index test for series.dot(df), refactoring
1 parent 9389250 commit 594c587

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

tests/system/small/test_multiindex.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,3 +1045,21 @@ def test_column_multi_index_dot_not_supported():
10451045
NotImplementedError, match="Multi-level column input is not supported"
10461046
):
10471047
bf1 @ bf2
1048+
1049+
1050+
def test_series_dot_df_column_multi_index():
1051+
left = [10, 11, 12, 13] # series data
1052+
right = [[0, 1, 2], [-2, 3, -4], [4, -5, 6], [6, 7, -8]] # dataframe data
1053+
1054+
multi_level_columns = pandas.MultiIndex.from_arrays(
1055+
[["col0", "col0", "col1"], ["col00", "col01", "col11"]]
1056+
)
1057+
1058+
bf_result = bpd.Series(left) @ bpd.DataFrame(right, columns=multi_level_columns)
1059+
pd_result = pandas.Series(left) @ pandas.DataFrame(
1060+
right, columns=multi_level_columns
1061+
)
1062+
1063+
pandas.testing.assert_series_equal(
1064+
bf_result.to_pandas(), pd_result, check_index_type=False, check_dtype=False
1065+
)

tests/system/small/test_series.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import pyarrow as pa # type: ignore
2323
import pytest
2424

25-
import bigframes.dataframe as dataframe
2625
import bigframes.pandas
2726
import bigframes.series as series
2827
from tests.system.utils import assert_pandas_df_equal, assert_series_equal
@@ -2267,24 +2266,21 @@ def test_dot(scalars_dfs):
22672266
assert bf_result == pd_result
22682267

22692268

2270-
def test_dot_df(scalars_dfs):
2271-
scalars_df, scalars_pandas_df = scalars_dfs
2272-
bf_result = scalars_df["int64_too"] @ scalars_df[["int64_col", "int64_too"]]
2273-
pd_result = (
2274-
scalars_pandas_df["int64_too"] @ scalars_pandas_df[["int64_col", "int64_too"]]
2275-
)
2269+
def test_dot_df(matrix_3by4_df, matrix_3by4_pandas_df):
2270+
bf_result = matrix_3by4_df["w"] @ matrix_3by4_df
2271+
pd_result = matrix_3by4_pandas_df["w"] @ matrix_3by4_pandas_df
22762272

22772273
pd.testing.assert_series_equal(
22782274
bf_result.to_pandas(), pd_result, check_index_type=False, check_dtype=False
22792275
)
22802276

22812277

2282-
def test_dot_df_inline(scalars_dfs):
2283-
left = [10, 11, 12, 13] # series data
2284-
right = [[0, 1], [-2, 3], [4, -5], [6, 7]] # dataframe data
2285-
2286-
bf_result = series.Series(left) @ dataframe.DataFrame(right)
2287-
pd_result = pd.Series(left) @ pd.DataFrame(right)
2278+
def test_dot_df_with_na(scalars_dfs):
2279+
scalars_df, scalars_pandas_df = scalars_dfs
2280+
bf_result = scalars_df["int64_too"] @ scalars_df[["int64_col", "int64_too"]]
2281+
pd_result = (
2282+
scalars_pandas_df["int64_too"] @ scalars_pandas_df[["int64_col", "int64_too"]]
2283+
)
22882284

22892285
pd.testing.assert_series_equal(
22902286
bf_result.to_pandas(), pd_result, check_index_type=False, check_dtype=False

0 commit comments

Comments
 (0)