jiayuasu commented on code in PR #925: URL: https://github.com/apache/sedona-db/pull/925#discussion_r3383154072
########## python/sedonadb/tests/expr/test_dataframe_cross_join.py: ########## @@ -0,0 +1,89 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import pandas as pd +import pandas.testing as pdt +import pytest + +from sedonadb.dataframe import DataFrame + + +def test_cross_join_basic(con): + left = con.create_data_frame(pd.DataFrame({"x": [1, 2]})) + right = con.create_data_frame(pd.DataFrame({"y": ["a", "b"]})) + out = left.cross_join(right).sort("x", "y").to_pandas() + pdt.assert_frame_equal( + out, + pd.DataFrame({"x": [1, 1, 2, 2], "y": ["a", "b", "a", "b"]}), + ) + + +def test_cross_join_multi_column_sides(con): + left = con.create_data_frame(pd.DataFrame({"x": [1, 2], "v": ["p", "q"]})) + right = con.create_data_frame(pd.DataFrame({"y": [10, 20], "w": ["r", "s"]})) + out = left.cross_join(right).sort("x", "y").to_pandas() + pdt.assert_frame_equal( + out, + pd.DataFrame( + { + "x": [1, 1, 2, 2], + "v": ["p", "p", "q", "q"], + "y": [10, 20, 10, 20], + "w": ["r", "s", "r", "s"], + } + ), + ) + + +def test_cross_join_single_row_left(con): + left = con.create_data_frame(pd.DataFrame({"x": [1]})) + right = con.create_data_frame(pd.DataFrame({"y": [10, 20, 30]})) + out = left.cross_join(right).sort("y").to_pandas() + pdt.assert_frame_equal( + out, + pd.DataFrame({"x": [1, 1, 1], "y": [10, 20, 30]}), + ) + + +def test_cross_join_empty_right(con): + left = con.create_data_frame(pd.DataFrame({"x": [1, 2]})) + right = con.create_data_frame(pd.DataFrame({"y": pd.Series([], dtype="int64")})) + out = left.cross_join(right).to_pandas() + assert len(out) == 0 + assert list(out.columns) == ["x", "y"] + + +def test_cross_join_with_aliases_disambiguates_names(con): + # When both sides share a column name, aliasing keeps the output + # rows but qualifiers vanish in to_pandas() — so just verify the + # join builds and produces the expected row count. + left = con.create_data_frame(pd.DataFrame({"k": [1, 2]})).alias("l") + right = con.create_data_frame(pd.DataFrame({"k": [10, 20, 30]})).alias("r") + out = left.cross_join(right) + assert out.count() == 6 + + +def test_cross_join_returns_lazy_dataframe(con): + left = con.create_data_frame(pd.DataFrame({"x": [1]})) + right = con.create_data_frame(pd.DataFrame({"y": [1]})) + assert isinstance(left.cross_join(right), DataFrame) Review Comment: Done in 0e0e5e9 — trimmed to the two tests (`test_cross_join_basic`, `test_cross_join_non_dataframe_other_raises`) and folded them into `test_dataframe_join.py`. Deleted the dedicated `test_dataframe_cross_join.py` file. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
