Skip to content

Commit

Permalink
[SPARK-46932] Clean up the imports in pyspark.pandas.test_*
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
1, remove unused import, variables
2, avoid double definition of variables

### Why are the changes needed?
code clean up

### Does this PR introduce _any_ user-facing change?
no

### How was this patch tested?
ci

### Was this patch authored or co-authored using generative AI tooling?
no

Closes #44967 from zhengruifeng/ps_test_cleanup.

Authored-by: Ruifeng Zheng <[email protected]>
Signed-off-by: Ruifeng Zheng <[email protected]>
  • Loading branch information
zhengruifeng committed Jan 31, 2024
1 parent 0871a6f commit e95e820
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 40 deletions.
10 changes: 5 additions & 5 deletions python/pyspark/pandas/tests/connect/test_parity_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
#
import unittest

from pyspark import pandas as ps
from pyspark.pandas.tests.test_categorical import CategoricalTestsMixin
from pyspark.testing.connectutils import ReusedConnectTestCase
from pyspark.testing.pandasutils import PandasOnSparkTestUtils, TestUtils


class CategoricalParityTests(
CategoricalTestsMixin, PandasOnSparkTestUtils, TestUtils, ReusedConnectTestCase
CategoricalTestsMixin,
PandasOnSparkTestUtils,
TestUtils,
ReusedConnectTestCase,
):
@property
def psdf(self):
return ps.from_pandas(self.pdf)
pass


if __name__ == "__main__":
Expand Down
21 changes: 6 additions & 15 deletions python/pyspark/pandas/tests/connect/test_parity_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,17 @@
#
import unittest

import pandas as pd
import numpy as np

from pyspark import pandas as ps
from pyspark.pandas.tests.test_extension import ExtensionTestsMixin
from pyspark.testing.connectutils import ReusedConnectTestCase
from pyspark.testing.pandasutils import PandasOnSparkTestUtils


class ExtensionParityTests(ExtensionTestsMixin, PandasOnSparkTestUtils, ReusedConnectTestCase):
@property
def pdf(self):
return pd.DataFrame(
{"a": [1, 2, 3, 4, 5, 6, 7, 8, 9], "b": [4, 5, 6, 3, 2, 1, 0, 0, 0]},
index=np.random.rand(9),
)

@property
def psdf(self):
return ps.from_pandas(self.pdf)
class ExtensionParityTests(
ExtensionTestsMixin,
PandasOnSparkTestUtils,
ReusedConnectTestCase,
):
pass


if __name__ == "__main__":
Expand Down
20 changes: 6 additions & 14 deletions python/pyspark/pandas/tests/connect/test_parity_numpy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,17 @@
#
import unittest

import pandas as pd

from pyspark import pandas as ps
from pyspark.pandas.tests.test_numpy_compat import NumPyCompatTestsMixin
from pyspark.testing.connectutils import ReusedConnectTestCase
from pyspark.testing.pandasutils import PandasOnSparkTestUtils


class NumPyCompatParityTests(NumPyCompatTestsMixin, PandasOnSparkTestUtils, ReusedConnectTestCase):
@property
def pdf(self):
return pd.DataFrame(
{"a": [1, 2, 3, 4, 5, 6, 7, 8, 9], "b": [4, 5, 6, 3, 2, 1, 0, 0, 0]},
index=[0, 1, 3, 5, 6, 8, 9, 9, 9],
)

@property
def psdf(self):
return ps.from_pandas(self.pdf)
class NumPyCompatParityTests(
NumPyCompatTestsMixin,
PandasOnSparkTestUtils,
ReusedConnectTestCase,
):
pass


if __name__ == "__main__":
Expand Down
12 changes: 10 additions & 2 deletions python/pyspark/pandas/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pandas.api.types import CategoricalDtype

import pyspark.pandas as ps
from pyspark.testing.pandasutils import ComparisonTestBase, TestUtils
from pyspark.testing.pandasutils import PandasOnSparkTestCase, TestUtils


class CategoricalTestsMixin:
Expand All @@ -35,6 +35,10 @@ def pdf(self):
},
)

@property
def psdf(self):
return ps.from_pandas(self.pdf)

@property
def df_pair(self):
return self.pdf, self.psdf
Expand Down Expand Up @@ -658,7 +662,11 @@ def test_set_categories(self):
)


class CategoricalTests(CategoricalTestsMixin, ComparisonTestBase, TestUtils):
class CategoricalTests(
CategoricalTestsMixin,
PandasOnSparkTestCase,
TestUtils,
):
pass


Expand Down
11 changes: 9 additions & 2 deletions python/pyspark/pandas/tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import pandas as pd

from pyspark import pandas as ps
from pyspark.testing.pandasutils import assert_produces_warning, ComparisonTestBase
from pyspark.testing.pandasutils import assert_produces_warning, PandasOnSparkTestCase
from pyspark.pandas.extensions import (
register_dataframe_accessor,
register_series_accessor,
Expand Down Expand Up @@ -74,6 +74,10 @@ def pdf(self):
index=np.random.rand(9),
)

@property
def psdf(self):
return ps.from_pandas(self.pdf)

@property
def accessor(self):
return CustomAccessor(self.psdf)
Expand Down Expand Up @@ -135,7 +139,10 @@ def __init__(self, data):
ps.Series([1, 2], dtype=object).bad


class ExtensionTests(ExtensionTestsMixin, ComparisonTestBase):
class ExtensionTests(
ExtensionTestsMixin,
PandasOnSparkTestCase,
):
pass


Expand Down
12 changes: 10 additions & 2 deletions python/pyspark/pandas/tests/test_numpy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from pyspark import pandas as ps
from pyspark.pandas import set_option, reset_option
from pyspark.testing.pandasutils import ComparisonTestBase
from pyspark.testing.pandasutils import PandasOnSparkTestCase
from pyspark.testing.sqlutils import SQLTestUtils


Expand All @@ -46,6 +46,10 @@ def pdf(self):
index=[0, 1, 3, 5, 6, 8, 9, 9, 9],
)

@property
def psdf(self):
return ps.from_pandas(self.pdf)

def test_np_add_series(self):
psdf = self.psdf
pdf = self.pdf
Expand Down Expand Up @@ -178,7 +182,11 @@ def test_np_spark_compat_frame(self):
reset_option("compute.ops_on_diff_frames")


class NumPyCompatTests(NumPyCompatTestsMixin, ComparisonTestBase, SQLTestUtils):
class NumPyCompatTests(
NumPyCompatTestsMixin,
PandasOnSparkTestCase,
SQLTestUtils,
):
pass


Expand Down

0 comments on commit e95e820

Please sign in to comment.