[
https://issues.apache.org/jira/browse/ARROW-2145?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16368619#comment-16368619
]
ASF GitHub Bot commented on ARROW-2145:
---------------------------------------
cpcloud commented on a change in pull request #1610: ARROW-2145/ARROW-2157:
[Python] Decimal conversion not working for NaN values
URL: https://github.com/apache/arrow/pull/1610#discussion_r168961327
##########
File path: cpp/src/arrow/python/builtin_convert.cc
##########
@@ -111,10 +122,22 @@ class ScalarVisitor {
ss << type->ToString();
return Status::Invalid(ss.str());
}
+ } else if (internal::PyDecimal_Check(obj)) {
+ // Don't infer anything if we encounter a Decimal('nan')
+ if (!internal::PyDecimal_ISNAN(obj)) {
+ int32_t precision;
+ int32_t scale;
+ RETURN_NOT_OK(internal::InferDecimalPrecisionAndScale(obj, &precision,
&scale));
+ max_decimal_precision_ = std::max(max_decimal_precision_, precision);
+ if (std::abs(max_decimal_scale_) < std::abs(scale)) {
Review comment:
Actually, reconsidering this based on your comment this really should be
just the max scale. Negative scale should contribute to precision only if it
would increase precision. The goal here is to "cast the widest net", ie the max
precision and max scale. Negative scale complicates things a tiny bit. I'll add
some commentary.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> [Python] Decimal conversion not working for NaN values
> ------------------------------------------------------
>
> Key: ARROW-2145
> URL: https://issues.apache.org/jira/browse/ARROW-2145
> Project: Apache Arrow
> Issue Type: Bug
> Components: C++, Python
> Affects Versions: 0.8.0
> Reporter: Antony Mayi
> Assignee: Phillip Cloud
> Priority: Major
> Labels: pull-request-available
>
> {code:python}
> import pyarrow as pa
> import pandas as pd
> import decimal
> pa.Table.from_pandas(pd.DataFrame({'a': [decimal.Decimal('1.1'),
> decimal.Decimal('NaN')]}))
> {code}
> throws following exception:
> {code}
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "pyarrow/table.pxi", line 875, in pyarrow.lib.Table.from_pandas
> (/arrow/python/build/temp.linux-x86_64-3.6/lib.cxx:44927)
> File "/lib/python3.6/site-packages/pyarrow/pandas_compat.py", line 350, in
> dataframe_to_arrays
> convert_types)]
> File "/lib/python3.6/site-packages/pyarrow/pandas_compat.py", line 349, in
> <listcomp>
> for c, t in zip(columns_to_convert,
> File "/lib/python3.6/site-packages/pyarrow/pandas_compat.py", line 345, in
> convert_column
> return pa.array(col, from_pandas=True, type=ty)
> File "pyarrow/array.pxi", line 170, in pyarrow.lib.array
> (/arrow/python/build/temp.linux-x86_64-3.6/lib.cxx:29224)
> File "pyarrow/array.pxi", line 70, in pyarrow.lib._ndarray_to_array
> (/arrow/python/build/temp.linux-x86_64-3.6/lib.cxx:28465)
> File "pyarrow/error.pxi", line 98, in pyarrow.lib.check_status
> (/arrow/python/build/temp.linux-x86_64-3.6/lib.cxx:9068)
> pyarrow.lib.ArrowException: Unknown error: an integer is required (got type
> str)
> {code}
> Same problem with other special decimal values like {{infinity}}.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)