ueshin commented on code in PR #53391: URL: https://github.com/apache/spark/pull/53391#discussion_r2608223210
########## python/pyspark/sql/tests/test_interchange.py: ########## @@ -0,0 +1,44 @@ +# +# 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 unittest +import pyarrow as pa +import pandas as pd +import pyspark.pandas as ps + +try: + import duckdb + + DUCKDB_TESTS = True +except ImportError: + DUCKDB_TESTS = False + + +class TestSparkArrowCStreamer(unittest.TestCase): Review Comment: ```suggestion @unittest.skipIf(not DUCKDB_TESTS, " ... ") class TestSparkArrowCStreamer(unittest.TestCase): ``` with the skip comment updated? ########## python/pyspark/sql/tests/test_interchange.py: ########## @@ -0,0 +1,44 @@ +# +# 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 unittest +import pyarrow as pa +import pandas as pd +import pyspark.pandas as ps + +try: + import duckdb + + DUCKDB_TESTS = True +except ImportError: + DUCKDB_TESTS = False + + +class TestSparkArrowCStreamer(unittest.TestCase): Review Comment: Also, we need to add `duckdb` in [dev/requirements.txt](https://github.com/devin-petersohn/spark/blob/b380413471c48febea84c40067239c109f6af7cd/dev/requirements.txt) to make this run? cc @HyukjinKwon ########## python/pyspark/interchange.py: ########## @@ -0,0 +1,88 @@ +# +# 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. +# +from typing import Iterator +import pyarrow Review Comment: nit: we usually use an alias name `pa` for `pyarrow`. ```suggestion import pyarrow as pa ``` ########## python/pyspark/sql/tests/test_interchange.py: ########## Review Comment: Could you add this file to [dev/sparktestsupport/modules.py](https://github.com/devin-petersohn/spark/blob/b380413471c48febea84c40067239c109f6af7cd/dev/sparktestsupport/modules.py) to let CI run the test? ########## python/pyspark/interchange.py: ########## @@ -0,0 +1,88 @@ +# +# 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. +# +from typing import Iterator +import pyarrow Review Comment: Could you separate the import block for builtin and the third party libraries? ########## python/pyspark/interchange.py: ########## Review Comment: Shall we move this to `pyspark.sql`? ########## python/pyspark/sql/tests/test_interchange.py: ########## @@ -0,0 +1,44 @@ +# +# 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 unittest +import pyarrow as pa +import pandas as pd +import pyspark.pandas as ps + +try: + import duckdb + + DUCKDB_TESTS = True +except ImportError: + DUCKDB_TESTS = False + + +class TestSparkArrowCStreamer(unittest.TestCase): + def test_spark_arrow_c_streamer(self): + if not DUCKDB_TESTS: + self.skipTest("duckdb is not installed") + + pdf = pd.DataFrame({"A": [1, "a"], "B": [2, "b"], "C": [3, "c"], "D": [4, "d"]}) + psdf = ps.from_pandas(pdf) + # Use Spark Arrow C Streamer to convert PyArrow Table to DuckDB relation + stream = pa.RecordBatchReader.from_stream(psdf) + assert isinstance(stream, pa.RecordBatchReader) + + # Verify the contents of the DuckDB relation + result = duckdb.execute("SELECT * from stream").fetchall() + expected = [(1, "a"), (2, "b"), (3, "c"), (4, "d")] + self.assertEqual(result, expected) Review Comment: Could you put the footer to run the tests? e.g., https://github.com/apache/spark/blob/b380413471c48febea84c40067239c109f6af7cd/python/pyspark/sql/tests/test_dataframe.py#L1199-L1208 -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
