xinrong-databricks commented on a change in pull request #32821: URL: https://github.com/apache/spark/pull/32821#discussion_r649365548
########## File path: python/pyspark/pandas/tests/data_type_ops/test_decimal_ops.py ########## @@ -0,0 +1,65 @@ +# +# 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 decimal as d + +import numpy as np +import pandas as pd + +from pyspark.pandas.data_type_ops.num_ops import DecimalOps +from pyspark import pandas as ps +from pyspark.pandas.tests.data_type_ops.testing_utils import TestCasesUtils +from pyspark.testing.pandasutils import PandasOnSparkTestCase + + +class DecimalOpsTest(PandasOnSparkTestCase, TestCasesUtils): + @property + def decimal_pser(self): + return pd.Series([d.Decimal(1.0), d.Decimal(2.0), d.Decimal(np.nan)]) + + @property + def decimal_psser(self): + return ps.from_pandas(self.decimal_pser) + + @property + def float_pser(self): + return pd.Series([1, 2, np.nan], dtype=float) + + @property + def float_psser(self): + return ps.from_pandas(self.float_pser) + + def test_datatype_ops(self): + psser = self.decimal_psser + self.assertIsInstance(psser._dtype_op, DecimalOps) + self.assertEqual(psser._dtype_op.pretty_name, "decimal") + + def test_isnull(self): + deci_psser = self.decimal_psser + float_psser = self.float_psser + + self.assertEqual(deci_psser._dtype_op.pretty_name, "decimal") + self.assertEqual(float_psser._dtype_op.pretty_name, "fractions") + + self.assert_eq( + pd.Series([False, False, False], index=[0, 1, 2]), + deci_psser._dtype_op.isnull(deci_psser), + ) + self.assert_eq( + pd.Series([False, False, True], index=[0, 1, 2]), + float_psser._dtype_op.isnull(float_psser), Review comment: Out of curiosity, why don't we compare with pandas `isnull` here? -- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
