|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# 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, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +import unittest |
| 18 | + |
| 19 | +import pandas as pd |
| 20 | + |
| 21 | +from pyspark import pandas as ps |
| 22 | +from pyspark.pandas.exceptions import PandasNotImplementedError |
| 23 | +from pyspark.testing.connectutils import ReusedConnectTestCase |
| 24 | +from pyspark.testing.pandasutils import PandasOnSparkTestUtils, TestUtils |
| 25 | + |
| 26 | + |
| 27 | +class ConnectPlottingTests(PandasOnSparkTestUtils, TestUtils, ReusedConnectTestCase): |
| 28 | + @property |
| 29 | + def pdf1(self): |
| 30 | + return pd.DataFrame( |
| 31 | + [[1, 2], [4, 5], [7, 8]], |
| 32 | + index=["cobra", "viper", None], |
| 33 | + columns=["max_speed", "shield"], |
| 34 | + ) |
| 35 | + |
| 36 | + @property |
| 37 | + def psdf1(self): |
| 38 | + return ps.from_pandas(self.pdf1) |
| 39 | + |
| 40 | + def test_unsupported_functions(self): |
| 41 | + with self.assertRaises(PandasNotImplementedError): |
| 42 | + self.psdf1.plot.hist() |
| 43 | + |
| 44 | + with self.assertRaises(PandasNotImplementedError): |
| 45 | + self.psdf1.plot.hist(bins=3) |
| 46 | + |
| 47 | + with self.assertRaises(PandasNotImplementedError): |
| 48 | + self.psdf1.plot.kde() |
| 49 | + |
| 50 | + with self.assertRaises(PandasNotImplementedError): |
| 51 | + self.psdf1.plot.kde(bw_method=3) |
| 52 | + |
| 53 | + with self.assertRaises(PandasNotImplementedError): |
| 54 | + self.psdf1.plot.density() |
| 55 | + |
| 56 | + with self.assertRaises(PandasNotImplementedError): |
| 57 | + self.psdf1.plot.density(bw_method=3) |
| 58 | + |
| 59 | + with self.assertRaises(PandasNotImplementedError): |
| 60 | + self.psdf1.shield.plot.hist() |
| 61 | + |
| 62 | + with self.assertRaises(PandasNotImplementedError): |
| 63 | + self.psdf1.shield.plot.hist(bins=3) |
| 64 | + |
| 65 | + with self.assertRaises(PandasNotImplementedError): |
| 66 | + self.psdf1.shield.plot.kde() |
| 67 | + |
| 68 | + with self.assertRaises(PandasNotImplementedError): |
| 69 | + self.psdf1.shield.plot.kde(bw_method=3) |
| 70 | + |
| 71 | + with self.assertRaises(PandasNotImplementedError): |
| 72 | + self.psdf1.shield.plot.density() |
| 73 | + |
| 74 | + with self.assertRaises(PandasNotImplementedError): |
| 75 | + self.psdf1.shield.plot.density(bw_method=3) |
| 76 | + |
| 77 | + def test_unsupported_kinds(self): |
| 78 | + with self.assertRaises(PandasNotImplementedError): |
| 79 | + self.psdf1.plot(kind="hist") |
| 80 | + |
| 81 | + with self.assertRaises(PandasNotImplementedError): |
| 82 | + self.psdf1.plot(kind="hist", bins=3) |
| 83 | + |
| 84 | + with self.assertRaises(PandasNotImplementedError): |
| 85 | + self.psdf1.plot(kind="kde") |
| 86 | + |
| 87 | + with self.assertRaises(PandasNotImplementedError): |
| 88 | + self.psdf1.plot(kind="kde", bw_method=3) |
| 89 | + |
| 90 | + with self.assertRaises(PandasNotImplementedError): |
| 91 | + self.psdf1.plot(kind="density") |
| 92 | + |
| 93 | + with self.assertRaises(PandasNotImplementedError): |
| 94 | + self.psdf1.plot(kind="density", bw_method=3) |
| 95 | + |
| 96 | + with self.assertRaises(PandasNotImplementedError): |
| 97 | + self.psdf1.shield.plot(kind="hist") |
| 98 | + |
| 99 | + with self.assertRaises(PandasNotImplementedError): |
| 100 | + self.psdf1.shield.plot(kind="hist", bins=3) |
| 101 | + |
| 102 | + with self.assertRaises(PandasNotImplementedError): |
| 103 | + self.psdf1.shield.plot(kind="kde") |
| 104 | + |
| 105 | + with self.assertRaises(PandasNotImplementedError): |
| 106 | + self.psdf1.shield.plot(kind="kde", bw_method=3) |
| 107 | + |
| 108 | + with self.assertRaises(PandasNotImplementedError): |
| 109 | + self.psdf1.shield.plot(kind="density") |
| 110 | + |
| 111 | + with self.assertRaises(PandasNotImplementedError): |
| 112 | + self.psdf1.shield.plot(kind="density", bw_method=3) |
| 113 | + |
| 114 | + |
| 115 | +if __name__ == "__main__": |
| 116 | + from pyspark.pandas.tests.connect.test_connect_plotting import * # noqa: F401 |
| 117 | + |
| 118 | + try: |
| 119 | + import xmlrunner # type: ignore[import] |
| 120 | + |
| 121 | + testRunner = xmlrunner.XMLTestRunner(output="target/test-reports", verbosity=2) |
| 122 | + except ImportError: |
| 123 | + testRunner = None |
| 124 | + unittest.main(testRunner=testRunner, verbosity=2) |
0 commit comments