MCPcopy Create free account
hub / github.com/apache/arrow / TestMixedPrecisionAndScale

Function TestMixedPrecisionAndScale

python/pyarrow/src/arrow/python/python_test.cc:747–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

745}
746
747Status TestMixedPrecisionAndScale() {
748 std::vector<std::string> strings{{"0.001", "1.01E5", "1.01E5"}};
749
750 OwnedRef list_ref(PyList_New(static_cast<Py_ssize_t>(strings.size())));
751 PyObject* list = list_ref.obj();
752
753 ASSERT_NE(list, nullptr);
754
755 OwnedRef decimal_constructor_;
756 OwnedRef decimal_module;
757 RETURN_NOT_OK(internal::ImportModule("decimal", &decimal_module));
758 RETURN_NOT_OK(
759 internal::ImportFromModule(decimal_module.obj(), "Decimal", &decimal_constructor_));
760 // PyList_SetItem steals a reference to the item so we don't decref it later
761 PyObject* decimal_constructor = decimal_constructor_.obj();
762 for (Py_ssize_t i = 0; i < static_cast<Py_ssize_t>(strings.size()); ++i) {
763 const int result = PyList_SetItem(
764 list, i, internal::DecimalFromString(decimal_constructor, strings.at(i)));
765 ASSERT_EQ(0, result);
766 }
767
768 auto arr = std::move(ConvertPySequence(list, nullptr, {})).ValueOrDie();
769 const auto& type = checked_cast<const DecimalType&>(*arr->type());
770
771 int32_t expected_precision = 9;
772 int32_t expected_scale = 3;
773 ASSERT_EQ(expected_precision, type.precision());
774 ASSERT_EQ(expected_scale, type.scale());
775
776 return Status::OK();
777}
778
779Status TestMixedPrecisionAndScaleSequenceConvert() {
780 OwnedRef decimal_constructor_;

Callers

nothing calls this directly

Calls 10

ImportModuleFunction · 0.85
ImportFromModuleFunction · 0.85
ConvertPySequenceFunction · 0.85
ValueOrDieMethod · 0.80
DecimalFromStringFunction · 0.70
OKFunction · 0.50
sizeMethod · 0.45
typeMethod · 0.45
precisionMethod · 0.45
scaleMethod · 0.45

Tested by

no test coverage detected