Skip to content

Commit 1cdc27d

Browse files
committed
style: fix pre-commit errors (license header and formatting)
1 parent 6dd8c18 commit 1cdc27d

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

python/sedona/spark/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474

7575
from pyspark.sql import DataFrame
7676

77+
7778
def to_sedonadb(self, connection=None):
7879
"""
7980
Converts a SedonaSpark DataFrame to a SedonaDB DataFrame.
@@ -83,11 +84,14 @@ def to_sedonadb(self, connection=None):
8384
try:
8485
import sedona.db
8586
except ImportError:
86-
raise ImportError("SedonaDB is not installed. Please install it using `pip install sedona-db`.")
87+
raise ImportError(
88+
"SedonaDB is not installed. Please install it using `pip install sedona-db`."
89+
)
8790

8891
if connection is None:
8992
connection = sedona.db.connect()
9093

9194
return connection.create_data_frame(dataframe_to_arrow(self))
9295

96+
9397
DataFrame.to_sedonadb = to_sedonadb

python/tests/test_to_sedonadb.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,61 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
117

218
import unittest
319
import sys
420
from unittest.mock import MagicMock, patch
521
from pyspark.sql import SparkSession, DataFrame
622
from sedona.spark import *
723

24+
825
class TestToSedonaDB(unittest.TestCase):
926

1027
def setUp(self):
1128
# Mock sedona.db to avoid ImportError
1229
self.mock_sedona_db = MagicMock()
1330
sys.modules["sedona.db"] = self.mock_sedona_db
1431
import sedona
32+
1533
sedona.db = self.mock_sedona_db
1634
self.spark = SparkSession.builder.getOrCreate()
1735

1836
def tearDown(self):
1937
if "sedona.db" in sys.modules:
2038
del sys.modules["sedona.db"]
2139
import sedona
40+
2241
if hasattr(sedona, "db"):
2342
del sedona.db
2443

25-
@patch('sedona.spark.dataframe_to_arrow')
44+
@patch("sedona.spark.dataframe_to_arrow")
2645
def test_to_sedonadb_no_connection(self, mock_dataframe_to_arrow):
2746
# Mock dependencies
2847
mock_arrow_table = MagicMock()
2948
mock_dataframe_to_arrow.return_value = mock_arrow_table
30-
49+
3150
mock_connection = MagicMock()
3251
self.mock_sedona_db.connect.return_value = mock_connection
33-
52+
3453
mock_sedonadb_df = MagicMock()
3554
mock_connection.create_data_frame.return_value = mock_sedonadb_df
3655

3756
# Create a dummy Spark DataFrame
3857
df = self.spark.range(1)
39-
58+
4059
# Call the method
4160
result = df.to_sedonadb()
4261

@@ -46,19 +65,19 @@ def test_to_sedonadb_no_connection(self, mock_dataframe_to_arrow):
4665
mock_connection.create_data_frame.assert_called_once_with(mock_arrow_table)
4766
self.assertEqual(result, mock_sedonadb_df)
4867

49-
@patch('sedona.spark.dataframe_to_arrow')
68+
@patch("sedona.spark.dataframe_to_arrow")
5069
def test_to_sedonadb_with_connection(self, mock_dataframe_to_arrow):
5170
# Mock dependencies
5271
mock_arrow_table = MagicMock()
5372
mock_dataframe_to_arrow.return_value = mock_arrow_table
54-
73+
5574
mock_connection = MagicMock()
5675
mock_sedonadb_df = MagicMock()
5776
mock_connection.create_data_frame.return_value = mock_sedonadb_df
5877

5978
# Create a dummy Spark DataFrame
6079
df = self.spark.range(1)
61-
80+
6281
# Call the method
6382
result = df.to_sedonadb(connection=mock_connection)
6483

@@ -67,5 +86,6 @@ def test_to_sedonadb_with_connection(self, mock_dataframe_to_arrow):
6786
mock_connection.create_data_frame.assert_called_once_with(mock_arrow_table)
6887
self.assertEqual(result, mock_sedonadb_df)
6988

70-
if __name__ == '__main__':
89+
90+
if __name__ == "__main__":
7191
unittest.main()

0 commit comments

Comments
 (0)