Skip to content

Commit

Permalink
Add other test from group TestInfer*
Browse files Browse the repository at this point in the history
  • Loading branch information
AlenkaF committed Sep 14, 2022
1 parent 6aa5d0f commit 8ff5341
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
50 changes: 50 additions & 0 deletions python/pyarrow/_pyarrow_cpp_tests.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_PythonDecimalToString():

assert string_result == decimal_string


def test_InferPrecisionAndScale():
cdef:
c_string decimal_string = b'-394029506937548693.42983'
Expand All @@ -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'
Expand All @@ -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(<PyObject*>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(<PyObject*>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(<PyObject*>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()
22 changes: 16 additions & 6 deletions python/pyarrow/tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 8ff5341

Please sign in to comment.