You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "ben w (JIRA)" <ji...@apache.org> on 2018/04/03 21:32:00 UTC

[jira] [Commented] (ARROW-2387) negative decimal values get spurious rescaling error

    [ https://issues.apache.org/jira/browse/ARROW-2387?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16424637#comment-16424637 ] 

ben w commented on ARROW-2387:
------------------------------

the issue would appear to come up here [https://github.com/apache/arrow/blob/master/cpp/src/arrow/util/decimal.cc#L833-L834]:

 

 
{code:java}
static bool RescaleWouldCauseDataLoss(const Decimal128& value, int32_t delta_scale,
                                      int32_t abs_delta_scale, Decimal128* result) {
    Decimal128 multiplier(ScaleMultipliers[abs_delta_scale]);
    if (delta_scale < 0) {
        DCHECK_NE(multiplier, 0);
        Decimal128 remainder;
        Status status = value.Divide(multiplier, result, &remainder);
        DCHECK(status.ok()) << status.message();
        return remainder != 0;
     }
     *result = value * multiplier;
     return *result < value;  // indeed, -1 * 1000000 is less than -1
}
{code}
 

 

> negative decimal values get spurious rescaling error
> ----------------------------------------------------
>
>                 Key: ARROW-2387
>                 URL: https://issues.apache.org/jira/browse/ARROW-2387
>             Project: Apache Arrow
>          Issue Type: Bug
>    Affects Versions: 0.9.0
>            Reporter: ben w
>            Assignee: Phillip Cloud
>            Priority: Major
>
> {code:java}
> $ python
> Python 2.7.12 (default, Nov 20 2017, 18:23:56)
> [GCC 5.4.0 20160609] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import pyarrow as pa, decimal
> >>> one = decimal.Decimal('1.000000')
> >>> neg_one = decimal.Decimal('-1.000000')
> >>> pa.array([one], pa.decimal128(24, 12))
> <pyarrow.lib.Decimal128Array object at 0x7f7f5ae85cb0>
> [
> Decimal('1.000000000000')
> ]
> >>> pa.array([neg_one], pa.decimal128(24, 12))
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "array.pxi", line 181, in pyarrow.lib.array
> File "array.pxi", line 36, in pyarrow.lib._sequence_to_array
> File "error.pxi", line 77, in pyarrow.lib.check_status
> pyarrow.lib.ArrowInvalid: Rescaling decimal value -1000000.000000 from original scale of 6 to new scale of 12 would cause data loss
> >>> pa.__version__
> '0.9.0'
> {code}
> not only is the error spurious, the decimal value has been multiplied by one million (i.e. 10 ** 6 and 6 is the difference in scales, but this is still pretty strange to me).



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)