diff --git a/python/pyarrow/_pyarrow_cpp_tests.pyx b/python/pyarrow/_pyarrow_cpp_tests.pyx index 44818d5a76124..05c5a2164c90f 100644 --- a/python/pyarrow/_pyarrow_cpp_tests.pyx +++ b/python/pyarrow/_pyarrow_cpp_tests.pyx @@ -40,6 +40,7 @@ def test_PythonDecimalToString(): assert string_result == decimal_string + def test_InferPrecisionAndScale(): cdef: c_string decimal_string = b'-394029506937548693.42983' @@ -55,6 +56,7 @@ def test_InferPrecisionAndScale(): assert expected_precision == metadata.precision() assert expected_scale == metadata.scale() + def test_InferPrecisionAndNegativeScale(): cdef: c_string decimal_string = b'-3.94042983E+10' @@ -69,3 +71,51 @@ def test_InferPrecisionAndNegativeScale(): assert expected_precision == metadata.precision() assert expected_scale == metadata.scale() + + +def test_TestInferAllLeadingZeros(): + cdef: + c_string decimal_string = b'0.001' + PyObject* python_object = DecimalFromString(Decimal, decimal_string) + DecimalMetadata metadata + int32_t expected_precision = 3 + int32_t expected_scale = 3 + + check_status(metadata.Update( + python_object) + ) + + assert expected_precision == metadata.precision() + assert expected_scale == metadata.scale() + + +def test_TestInferAllLeadingZerosExponentialNotationPositive(): + cdef: + c_string decimal_string = b'0.01E5' + PyObject* python_object = DecimalFromString(Decimal, decimal_string) + DecimalMetadata metadata + int32_t expected_precision = 4 + int32_t expected_scale = 0 + + check_status(metadata.Update( + python_object) + ) + + assert expected_precision == metadata.precision() + assert expected_scale == metadata.scale() + + +def test_TestInferAllLeadingZerosExponentialNotationNegative(): + cdef: + c_string decimal_string = b'0.01E3' + PyObject* python_object = DecimalFromString(Decimal, decimal_string) + DecimalMetadata metadata + int32_t expected_precision = 2 + int32_t expected_scale = 0 + + check_status(metadata.Update( + python_object) + ) + + assert expected_precision == metadata.precision() + assert expected_scale == metadata.scale() diff --git a/python/pyarrow/tests/test_python.py b/python/pyarrow/tests/test_python.py index f2994595f248d..cb4c1b27a18ce 100644 --- a/python/pyarrow/tests/test_python.py +++ b/python/pyarrow/tests/test_python.py @@ -30,18 +30,28 @@ # if callable(item) and name.startswith("test_"): # setattr(sys.modules[__name__], name, item) -from pyarrow._pyarrow_cpp_tests import (test_PythonDecimalToString, # noqa - test_InferPrecisionAndScale, - test_InferPrecisionAndNegativeScale) +import pyarrow._pyarrow_cpp_tests as t # noqa def test_python_decimal_to_string(): - test_PythonDecimalToString() + t.test_PythonDecimalToString() def test_infer_precision_and_scale(): - test_InferPrecisionAndScale() + t.test_InferPrecisionAndScale() def test_infer_precision_and_negative_scale(): - test_InferPrecisionAndNegativeScale() + t.test_InferPrecisionAndNegativeScale() + + +def test_infer_all_leading_zeros(): + t.test_TestInferAllLeadingZeros() + + +def test_infer_all_leading_zeros_e_pos(): + t.test_TestInferAllLeadingZerosExponentialNotationPositive() + + +def test_infer_all_leading_zeros_e_neg(): + t.test_TestInferAllLeadingZerosExponentialNotationNegative()