You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by cp...@apache.org on 2018/04/13 20:02:33 UTC
[arrow] branch master updated: ARROW-2387: [Python] Flip test for
rescale loss if value < 0
This is an automated email from the ASF dual-hosted git repository.
cpcloud pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 7de1264 ARROW-2387: [Python] Flip test for rescale loss if value < 0
7de1264 is described below
commit 7de1264c7230f0a9ae8261bb08ea6b57d2b51e7c
Author: Ben Wolfson <be...@affirm.com>
AuthorDate: Fri Apr 13 16:02:28 2018 -0400
ARROW-2387: [Python] Flip test for rescale loss if value < 0
Author: Ben Wolfson <be...@affirm.com>
Closes #1832 from bwo/ARROW-2387 and squashes the following commits:
6b69be34 <Ben Wolfson> address comments
30a02fb7 <Ben Wolfson> formatting of python-test.cc
793b416d <Ben Wolfson> flip test for rescale loss if value < 0
---
cpp/src/arrow/python/python-test.cc | 10 ++++++++++
cpp/src/arrow/util/decimal.cc | 2 +-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/cpp/src/arrow/python/python-test.cc b/cpp/src/arrow/python/python-test.cc
index 293255b..3ea814f 100644
--- a/cpp/src/arrow/python/python-test.cc
+++ b/cpp/src/arrow/python/python-test.cc
@@ -247,6 +247,16 @@ TEST_F(DecimalTest, FromPythonDecimalRescaleTruncateable) {
ASSERT_EQ(100, value.low_bits());
}
+TEST_F(DecimalTest, FromPythonNegativeDecimalRescale) {
+ Decimal128 value;
+ OwnedRef python_decimal(this->CreatePythonDecimal("-1.000"));
+ auto type = ::arrow::decimal(10, 9);
+ const auto& decimal_type = static_cast<const DecimalType&>(*type);
+ ASSERT_OK(
+ internal::DecimalFromPythonDecimal(python_decimal.obj(), decimal_type, &value));
+ ASSERT_EQ(-1000000000, value);
+}
+
TEST_F(DecimalTest, TestOverflowFails) {
Decimal128 value;
OwnedRef python_decimal(
diff --git a/cpp/src/arrow/util/decimal.cc b/cpp/src/arrow/util/decimal.cc
index 9e5e3dd..668da6f 100644
--- a/cpp/src/arrow/util/decimal.cc
+++ b/cpp/src/arrow/util/decimal.cc
@@ -843,7 +843,7 @@ static bool RescaleWouldCauseDataLoss(const Decimal128& value, int32_t delta_sca
}
*result = value * multiplier;
- return *result < value;
+ return (value < 0) ? *result > value : *result < value;
}
Status Decimal128::Rescale(int32_t original_scale, int32_t new_scale,
--
To stop receiving notification emails like this one, please contact
cpcloud@apache.org.