You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "llama90 (via GitHub)" <gi...@apache.org> on 2024/03/23 10:32:05 UTC
[PR] GH-40282: Use C++ type traits [arrow]
llama90 opened a new pull request, #40761:
URL: https://github.com/apache/arrow/pull/40761
<!--
Thanks for opening a pull request!
If this is your first pull request you can find detailed information on how
to contribute here:
* [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
* [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
Then could you also rename the pull request title in the following format?
GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
or
MINOR: [${COMPONENT}] ${SUMMARY}
In the case of PARQUET issues on JIRA the title also supports:
PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
-->
### Rationale for this change
Use C++ type traits to avoid redefining in Python
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
### What changes are included in this PR?
Changed all functions that check types in `type_traits.h` so that they can be used in Python.
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
### Are these changes tested?
Yes
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
### Are there any user-facing changes?
Yes
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
-->
<!-- **This PR includes breaking changes to public APIs.** -->
<!--
Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
-->
<!-- **This PR contains a "Critical Fix".** -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1553561365
##########
python/pyarrow/types.py:
##########
@@ -59,92 +69,92 @@ def is_null(t):
@doc(is_null, datatype="boolean")
def is_boolean(t):
- return t.id == lib.Type_BOOL
+ return _is_primitive(t) and _bit_width(t) == 1
Review Comment:
Is my understanding correct? Does this mean that `types.pxi` should be implemented using functions exposed in `type_traits.h` and `types.py` should only call functions with `_` as a prefix? Sorry for asking again... 🥲
- pyarrow/types.pxi
```
def _is_boolean(data_type):
"""
This function checks whether the `data_type` is a boolean type.
Parameters
----------
data_type : DataType
The data type to check
Returns
-------
bool
True if `data_type` is a boolean type, False otherwise.
"""
return _is_primitive(data_type) and _bit_width(data_type) == 1
```
- types.py
```
def is_boolean(t):
return _is_boolean(t)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "felipecrv (via GitHub)" <gi...@apache.org>.
felipecrv commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2116524241
The predicates around lists and list-views are quite confusing (for backwards compatibility reasons) with some are deprecated. Is it possible to not repeat these on the Python side or we have to keep exactly the same structure that we have in C++?
https://gist.github.com/felipecrv/3c02f3784221d946dec1b031c6d400db
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2117612935
I have come too far in this PR to make changes, so I have closed it and opened a new one.
- https://github.com/apache/arrow/pull/41709
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1537409892
##########
python/pyarrow/type_traits.pxi:
##########
@@ -0,0 +1,394 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from pyarrow.includes.libarrow cimport (is_integer,
+ is_signed_integer,
+ is_unsigned_integer,
+ is_floating,
+ is_numeric,
+ is_decimal,
+ is_run_end_type,
+ is_primitive,
+ is_base_binary_like,
+ is_binary_like,
+ is_large_binary_like,
+ is_binary,
+ is_string,
+ is_temporal,
+ is_time,
+ is_date,
+ is_interval,
+ is_dictionary,
+ is_fixed_size_binary,
+ is_fixed_width,
+ is_var_length_list,
+ is_list,
+ is_list_like,
+ is_var_length_list_like,
+ is_list_view,
+ is_nested,
+ is_union,
+ bit_width,
+ offset_bit_width)
+
+
+def is_integer_type(data_type):
+ """
+ Check if the data type is an integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_integer(data_type.id)
+
+
+def is_signed_integer_type(data_type):
+ """
+ Check if the data type is a signed integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_signed_integer(data_type.id)
+
+
+def is_unsigned_integer_type(data_type):
+ """
+ Check if the data type is an unsigned integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_unsigned_integer(data_type.id)
+
+
+def is_floating_type(data_type):
+ """
+ Check if the data type is a floating type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_floating(data_type.id)
+
+
+def is_numeric_type(data_type):
+ """
+ Check if the data type is a numeric type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_numeric(data_type.id)
+
+
+def is_decimal_type(data_type):
+ """
+ Check if the data type is a decimal type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_decimal(data_type.id)
+
+
+def is_run_end_type_py(data_type):
+ """
+ Check if the data type is a run end type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_run_end_type(data_type.id)
+
+
+def is_primitive_type(data_type):
+ """
+ Check if the data type is a primitive type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_primitive(data_type.id)
+
+
+def is_base_binary_like_type(data_type):
+ """
+ Check if the data type is a base_binary_like type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_base_binary_like(data_type.id)
+
+
+def is_binary_like_type(data_type):
+ """
+ Check if the data type is a _binary_like type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_binary_like(data_type.id)
+
+
+def is_large_binary_like_type(data_type):
+ """
+ Check if the data type is a large_binary_like type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_large_binary_like(data_type.id)
+
+
+def is_binary_type(data_type):
+ """
+ Check if the data type is a binary type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_binary(data_type.id)
+
+
+def is_string_type(data_type):
+ """
+ Check if the data type is a string type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_string(data_type.id)
+
+
+def is_temporal_type(data_type):
+ """
+ Check if the data type is a temporal type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_temporal(data_type.id)
+
+
+def is_time_type(data_type):
+ """
+ Check if the data type is a time type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_time(data_type.id)
+
+
+def is_date_type(data_type):
+ """
+ Check if the data type is a date type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_date(data_type.id)
+
+
+def is_interval_type(data_type):
+ """
+ Check if the data type is a interval type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_interval(data_type.id)
+
+
+def is_dictionary_type(data_type):
+ """
+ Check if the data type is a dictionary type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_dictionary(data_type.id)
+
+
+def is_fixed_size_binary_type(data_type):
+ """
+ Check if the data type is a fixed_size_binary type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_fixed_size_binary(data_type.id)
+
+
+def is_fixed_width_type(data_type):
+ """
+ Check if the data type is a fixed_width type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_fixed_width(data_type.id)
+
+
+def is_var_length_list_type(data_type):
+ """
+ Check if the data type is a var_length_list type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_var_length_list(data_type.id)
+
+
+def is_list_type(data_type):
+ """
+ Check if the data type is a list type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_list(data_type.id)
+
+
+def is_list_like_type(data_type):
+ """
+ Check if the data type is a list_like type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_list_like(data_type.id)
+
+
+def is_var_length_list_like_type(data_type):
+ """
+ Check if the data type is a var_length_list_like type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_var_length_list_like(data_type.id)
+
+
+def is_list_view_type(data_type):
+ """
+ Check if the data type is a list_view type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_list_view(data_type.id)
+
+
+def is_nested_type(data_type):
+ """
+ Check if the data type is a nested type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_nested(data_type.id)
+
+
+def is_union_type(data_type):
+ """
+ Check if the data type is a union type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_union(data_type.id)
+
+
+def is_bit_width_type(data_type):
+ """
+ Check if the data type is a bit_width type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return bit_width(data_type.id)
+
+
+def is_offset_bit_width_type(data_type):
+ """
+ Check if the data type is a offset_bit_width type.
Review Comment:
Even I don't know what a "offset_bit_width type" is supposed to be...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1553499475
##########
python/pyarrow/types.py:
##########
@@ -59,92 +69,92 @@ def is_null(t):
@doc(is_null, datatype="boolean")
def is_boolean(t):
- return t.id == lib.Type_BOOL
+ return _is_primitive(t) and _bit_width(t) == 1
Review Comment:
I mean remove `_is_primitive` and other functions, and implement `is_boolean` etc. in `types.pxi`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1537411762
##########
python/pyarrow/types.py:
##########
@@ -20,29 +20,47 @@
from pyarrow.lib import (is_boolean_value, # noqa
is_integer_value,
- is_float_value)
+ is_float_value,
+ is_integer_type,
+ is_signed_integer_type,
+ is_unsigned_integer_type,
+ is_floating_type,
+ is_numeric_type,
+ is_decimal_type,
+ is_run_end_type_py,
+ is_primitive_type,
+ is_base_binary_like_type,
+ is_binary_like_type,
+ is_large_binary_like_type,
+ is_binary_type,
+ is_string_type,
+ is_temporal_type,
+ is_time_type,
+ is_date_type,
+ is_interval_type,
+ is_dictionary_type,
+ is_fixed_size_binary_type,
+ is_fixed_width_type,
+ is_var_length_list_type,
+ is_list_type,
+ is_list_like_type,
+ is_var_length_list_like_type,
+ is_list_view_type,
+ is_nested_type,
+ is_union_type,
+ is_bit_width_type,
+ is_offset_bit_width_type)
import pyarrow.lib as lib
from pyarrow.util import doc
-_SIGNED_INTEGER_TYPES = {lib.Type_INT8, lib.Type_INT16, lib.Type_INT32,
- lib.Type_INT64}
-_UNSIGNED_INTEGER_TYPES = {lib.Type_UINT8, lib.Type_UINT16, lib.Type_UINT32,
- lib.Type_UINT64}
-_INTEGER_TYPES = _SIGNED_INTEGER_TYPES | _UNSIGNED_INTEGER_TYPES
-_FLOATING_TYPES = {lib.Type_HALF_FLOAT, lib.Type_FLOAT, lib.Type_DOUBLE}
-_DECIMAL_TYPES = {lib.Type_DECIMAL128, lib.Type_DECIMAL256}
_DATE_TYPES = {lib.Type_DATE32, lib.Type_DATE64}
_TIME_TYPES = {lib.Type_TIME32, lib.Type_TIME64}
_INTERVAL_TYPES = {lib.Type_INTERVAL_MONTH_DAY_NANO}
_TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
Review Comment:
Indeed, it would be nicer if the definitions matched. Other than that, there's no strong reason to prefer one definition over the other, IMHO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: Use C++ type traits [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1537398776
##########
python/pyarrow/types.py:
##########
@@ -64,17 +82,17 @@ def is_boolean(t):
@doc(is_null, datatype="any integer")
def is_integer(t):
- return t.id in _INTEGER_TYPES
+ return is_integer_type(t)
@doc(is_null, datatype="signed integer")
def is_signed_integer(t):
- return t.id in _SIGNED_INTEGER_TYPES
+ return is_signed_integer_type(t)
@doc(is_null, datatype="unsigned integer")
def is_unsigned_integer(t):
- return t.id in _UNSIGNED_INTEGER_TYPES
+ return is_unsigned_integer_type(t)
@doc(is_null, datatype="int8")
Review Comment:
I would suggest checking for `bit_width(t)` together with `is_integer_type(t)`. Both are exposed in this PR.
##########
python/pyarrow/types.py:
##########
@@ -20,29 +20,47 @@
from pyarrow.lib import (is_boolean_value, # noqa
is_integer_value,
- is_float_value)
+ is_float_value,
+ is_integer_type,
+ is_signed_integer_type,
+ is_unsigned_integer_type,
+ is_floating_type,
+ is_numeric_type,
+ is_decimal_type,
+ is_run_end_type_py,
+ is_primitive_type,
+ is_base_binary_like_type,
+ is_binary_like_type,
+ is_large_binary_like_type,
+ is_binary_type,
+ is_string_type,
+ is_temporal_type,
+ is_time_type,
+ is_date_type,
+ is_interval_type,
+ is_dictionary_type,
+ is_fixed_size_binary_type,
+ is_fixed_width_type,
+ is_var_length_list_type,
+ is_list_type,
+ is_list_like_type,
+ is_var_length_list_like_type,
+ is_list_view_type,
+ is_nested_type,
+ is_union_type,
+ is_bit_width_type,
+ is_offset_bit_width_type)
import pyarrow.lib as lib
from pyarrow.util import doc
-_SIGNED_INTEGER_TYPES = {lib.Type_INT8, lib.Type_INT16, lib.Type_INT32,
- lib.Type_INT64}
-_UNSIGNED_INTEGER_TYPES = {lib.Type_UINT8, lib.Type_UINT16, lib.Type_UINT32,
- lib.Type_UINT64}
-_INTEGER_TYPES = _SIGNED_INTEGER_TYPES | _UNSIGNED_INTEGER_TYPES
-_FLOATING_TYPES = {lib.Type_HALF_FLOAT, lib.Type_FLOAT, lib.Type_DOUBLE}
-_DECIMAL_TYPES = {lib.Type_DECIMAL128, lib.Type_DECIMAL256}
_DATE_TYPES = {lib.Type_DATE32, lib.Type_DATE64}
_TIME_TYPES = {lib.Type_TIME32, lib.Type_TIME64}
_INTERVAL_TYPES = {lib.Type_INTERVAL_MONTH_DAY_NANO}
_TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
Review Comment:
It is a bit annoying they are being handled differently.
We can use multiple C++ functions to get what is expected in Python, for example:
```python
is_temporal_type(t) and is_interval_type(t) and is_duration(t) # assuming is_duration_type can be referenced from C++?
```
but ideally the definitions would match between C++ and Python.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1562439775
##########
python/pyarrow/types.py:
##########
@@ -20,295 +20,54 @@
from pyarrow.lib import (is_boolean_value, # noqa
is_integer_value,
- is_float_value)
-
-import pyarrow.lib as lib
-from pyarrow.util import doc
-
-
-_SIGNED_INTEGER_TYPES = {lib.Type_INT8, lib.Type_INT16, lib.Type_INT32,
- lib.Type_INT64}
-_UNSIGNED_INTEGER_TYPES = {lib.Type_UINT8, lib.Type_UINT16, lib.Type_UINT32,
- lib.Type_UINT64}
-_INTEGER_TYPES = _SIGNED_INTEGER_TYPES | _UNSIGNED_INTEGER_TYPES
-_FLOATING_TYPES = {lib.Type_HALF_FLOAT, lib.Type_FLOAT, lib.Type_DOUBLE}
-_DECIMAL_TYPES = {lib.Type_DECIMAL128, lib.Type_DECIMAL256}
-_DATE_TYPES = {lib.Type_DATE32, lib.Type_DATE64}
-_TIME_TYPES = {lib.Type_TIME32, lib.Type_TIME64}
-_INTERVAL_TYPES = {lib.Type_INTERVAL_MONTH_DAY_NANO}
-_TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
- lib.Type_DURATION} | _TIME_TYPES | _DATE_TYPES |
- _INTERVAL_TYPES)
-_UNION_TYPES = {lib.Type_SPARSE_UNION, lib.Type_DENSE_UNION}
-_NESTED_TYPES = {lib.Type_LIST, lib.Type_FIXED_SIZE_LIST, lib.Type_LARGE_LIST,
- lib.Type_LIST_VIEW, lib.Type_LARGE_LIST_VIEW,
- lib.Type_STRUCT, lib.Type_MAP} | _UNION_TYPES
-
-
-@doc(datatype="null")
-def is_null(t):
- """
- Return True if value is an instance of type: {datatype}.
-
- Parameters
- ----------
- t : DataType
- """
- return t.id == lib.Type_NA
-
-
-@doc(is_null, datatype="boolean")
-def is_boolean(t):
- return t.id == lib.Type_BOOL
-
-
-@doc(is_null, datatype="any integer")
-def is_integer(t):
- return t.id in _INTEGER_TYPES
-
-
-@doc(is_null, datatype="signed integer")
-def is_signed_integer(t):
- return t.id in _SIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="unsigned integer")
-def is_unsigned_integer(t):
- return t.id in _UNSIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="int8")
-def is_int8(t):
- return t.id == lib.Type_INT8
-
-
-@doc(is_null, datatype="int16")
-def is_int16(t):
- return t.id == lib.Type_INT16
-
-
-@doc(is_null, datatype="int32")
-def is_int32(t):
- return t.id == lib.Type_INT32
-
-
-@doc(is_null, datatype="int64")
-def is_int64(t):
- return t.id == lib.Type_INT64
-
-
-@doc(is_null, datatype="uint8")
-def is_uint8(t):
- return t.id == lib.Type_UINT8
-
-
-@doc(is_null, datatype="uint16")
-def is_uint16(t):
- return t.id == lib.Type_UINT16
-
-
-@doc(is_null, datatype="uint32")
-def is_uint32(t):
- return t.id == lib.Type_UINT32
-
-
-@doc(is_null, datatype="uint64")
-def is_uint64(t):
- return t.id == lib.Type_UINT64
-
-
-@doc(is_null, datatype="floating point numeric")
-def is_floating(t):
- return t.id in _FLOATING_TYPES
-
-
-@doc(is_null, datatype="float16 (half-precision)")
-def is_float16(t):
- return t.id == lib.Type_HALF_FLOAT
-
-
-@doc(is_null, datatype="float32 (single precision)")
-def is_float32(t):
- return t.id == lib.Type_FLOAT
-
-
-@doc(is_null, datatype="float64 (double precision)")
-def is_float64(t):
- return t.id == lib.Type_DOUBLE
-
-
-@doc(is_null, datatype="list")
-def is_list(t):
- return t.id == lib.Type_LIST
-
-
-@doc(is_null, datatype="large list")
-def is_large_list(t):
- return t.id == lib.Type_LARGE_LIST
-
-
-@doc(is_null, datatype="fixed size list")
-def is_fixed_size_list(t):
- return t.id == lib.Type_FIXED_SIZE_LIST
-
-
-@doc(is_null, datatype="list view")
-def is_list_view(t):
- return t.id == lib.Type_LIST_VIEW
-
-
-@doc(is_null, datatype="large list view")
-def is_large_list_view(t):
- return t.id == lib.Type_LARGE_LIST_VIEW
-
-
-@doc(is_null, datatype="struct")
-def is_struct(t):
- return t.id == lib.Type_STRUCT
-
-
-@doc(is_null, datatype="union")
-def is_union(t):
- return t.id in _UNION_TYPES
-
-
-@doc(is_null, datatype="nested type")
-def is_nested(t):
- return t.id in _NESTED_TYPES
-
-
-@doc(is_null, datatype="run-end encoded")
-def is_run_end_encoded(t):
- return t.id == lib.Type_RUN_END_ENCODED
-
-
-@doc(is_null, datatype="date, time, timestamp or duration")
-def is_temporal(t):
- return t.id in _TEMPORAL_TYPES
-
-
-@doc(is_null, datatype="timestamp")
-def is_timestamp(t):
- return t.id == lib.Type_TIMESTAMP
-
-
-@doc(is_null, datatype="duration")
-def is_duration(t):
- return t.id == lib.Type_DURATION
-
-
-@doc(is_null, datatype="time")
-def is_time(t):
- return t.id in _TIME_TYPES
-
-
-@doc(is_null, datatype="time32")
-def is_time32(t):
- return t.id == lib.Type_TIME32
-
-
-@doc(is_null, datatype="time64")
-def is_time64(t):
- return t.id == lib.Type_TIME64
-
-
-@doc(is_null, datatype="variable-length binary")
-def is_binary(t):
- return t.id == lib.Type_BINARY
-
-
-@doc(is_null, datatype="large variable-length binary")
-def is_large_binary(t):
- return t.id == lib.Type_LARGE_BINARY
-
-
-@doc(method="is_string")
-def is_unicode(t):
- """
- Alias for {method}.
-
- Parameters
- ----------
- t : DataType
- """
- return is_string(t)
-
-
-@doc(is_null, datatype="string (utf8 unicode)")
-def is_string(t):
- return t.id == lib.Type_STRING
-
-
-@doc(is_unicode, method="is_large_string")
-def is_large_unicode(t):
- return is_large_string(t)
-
-
-@doc(is_null, datatype="large string (utf8 unicode)")
-def is_large_string(t):
- return t.id == lib.Type_LARGE_STRING
-
-
-@doc(is_null, datatype="fixed size binary")
-def is_fixed_size_binary(t):
- return t.id == lib.Type_FIXED_SIZE_BINARY
-
-
-@doc(is_null, datatype="variable-length binary view")
-def is_binary_view(t):
- return t.id == lib.Type_BINARY_VIEW
-
-
-@doc(is_null, datatype="variable-length string (utf-8) view")
-def is_string_view(t):
- return t.id == lib.Type_STRING_VIEW
-
-
-@doc(is_null, datatype="date")
-def is_date(t):
- return t.id in _DATE_TYPES
-
-
-@doc(is_null, datatype="date32 (days)")
-def is_date32(t):
- return t.id == lib.Type_DATE32
-
-
-@doc(is_null, datatype="date64 (milliseconds)")
-def is_date64(t):
- return t.id == lib.Type_DATE64
-
-
-@doc(is_null, datatype="map")
-def is_map(t):
- return t.id == lib.Type_MAP
-
-
-@doc(is_null, datatype="decimal")
-def is_decimal(t):
- return t.id in _DECIMAL_TYPES
-
-
-@doc(is_null, datatype="decimal128")
-def is_decimal128(t):
- return t.id == lib.Type_DECIMAL128
-
-
-@doc(is_null, datatype="decimal256")
-def is_decimal256(t):
- return t.id == lib.Type_DECIMAL256
-
-
-@doc(is_null, datatype="dictionary-encoded")
-def is_dictionary(t):
- return t.id == lib.Type_DICTIONARY
-
-
-@doc(is_null, datatype="interval")
-def is_interval(t):
- return t.id == lib.Type_INTERVAL_MONTH_DAY_NANO
-
-
-@doc(is_null, datatype="primitive type")
-def is_primitive(t):
- return lib._is_primitive(t.id)
+ is_float_value,
+ ensure_type,
+ _is_integer as is_integer,
Review Comment:
Can you explain this in more detail?
It cannot have the same name as a function imported via `cdef extern from "arrow/type_traits.h" namespace "arrow":`.
Also, it appears that if I declare it using a different name to avoid conflict, I will eventually have to redeclare it using `as`.
If I expose `as` without prefixing it, compatibility seems to be broken.
<details><summary>error</summary>
```
============================== 1 failed in 0.20s ===============================
FAILED [100%]
pyarrow/tests/test_pandas.py:4465 (test_chunked_array_to_pandas_types_mapper)
@pytest.mark.pandas
def test_chunked_array_to_pandas_types_mapper():
# https://issues.apache.org/jira/browse/ARROW-9664
if Version(pd.__version__) < Version("1.2.0"):
pytest.skip("Float64Dtype extension dtype missing")
data = pa.chunked_array([pa.array([1, 2, 3], pa.int64())])
assert isinstance(data, pa.ChunkedArray)
# Test with mapper function
types_mapper = {pa.int64(): pd.Int64Dtype()}.get
> result = data.to_pandas(types_mapper=types_mapper)
tests/test_pandas.py:4477:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pyarrow/array.pxi:899: in pyarrow.lib._PandasConvertible.to_pandas
???
pyarrow/table.pxi:475: in pyarrow.lib.ChunkedArray._to_pandas
???
pyarrow/array.pxi:1917: in pyarrow.lib._array_like_to_pandas
???
/Users/lama/anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/numeric.py:100: in __from_arrow__
data, mask = pyarrow_array_to_numpy_and_mask(array, dtype=self.numpy_dtype)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = <pyarrow.lib.Int64Array object at 0x14d521360>
[
1,
2,
3
]
dtype = dtype('int64')
def pyarrow_array_to_numpy_and_mask(
arr, dtype: np.dtype
) -> tuple[np.ndarray, np.ndarray]:
"""
Convert a primitive pyarrow.Array to a numpy array and boolean mask based
on the buffers of the Array.
At the moment pyarrow.BooleanArray is not supported.
Parameters
----------
arr : pyarrow.Array
dtype : numpy.dtype
Returns
-------
(data, mask)
Tuple of two numpy arrays with the raw data (with specified dtype) and
a boolean mask (validity mask, so False means missing)
"""
dtype = np.dtype(dtype)
> if pyarrow.types.is_null(arr.type):
E AttributeError: module 'pyarrow.types' has no attribute 'is_null'
/Users/lama/anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/arrow/_arrow_utils.py:45: AttributeError
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1562439996
##########
python/pyarrow/types.py:
##########
@@ -20,295 +20,54 @@
from pyarrow.lib import (is_boolean_value, # noqa
is_integer_value,
- is_float_value)
-
-import pyarrow.lib as lib
-from pyarrow.util import doc
-
-
-_SIGNED_INTEGER_TYPES = {lib.Type_INT8, lib.Type_INT16, lib.Type_INT32,
- lib.Type_INT64}
-_UNSIGNED_INTEGER_TYPES = {lib.Type_UINT8, lib.Type_UINT16, lib.Type_UINT32,
- lib.Type_UINT64}
-_INTEGER_TYPES = _SIGNED_INTEGER_TYPES | _UNSIGNED_INTEGER_TYPES
-_FLOATING_TYPES = {lib.Type_HALF_FLOAT, lib.Type_FLOAT, lib.Type_DOUBLE}
-_DECIMAL_TYPES = {lib.Type_DECIMAL128, lib.Type_DECIMAL256}
-_DATE_TYPES = {lib.Type_DATE32, lib.Type_DATE64}
-_TIME_TYPES = {lib.Type_TIME32, lib.Type_TIME64}
-_INTERVAL_TYPES = {lib.Type_INTERVAL_MONTH_DAY_NANO}
-_TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
- lib.Type_DURATION} | _TIME_TYPES | _DATE_TYPES |
- _INTERVAL_TYPES)
-_UNION_TYPES = {lib.Type_SPARSE_UNION, lib.Type_DENSE_UNION}
-_NESTED_TYPES = {lib.Type_LIST, lib.Type_FIXED_SIZE_LIST, lib.Type_LARGE_LIST,
- lib.Type_LIST_VIEW, lib.Type_LARGE_LIST_VIEW,
- lib.Type_STRUCT, lib.Type_MAP} | _UNION_TYPES
-
-
-@doc(datatype="null")
-def is_null(t):
- """
- Return True if value is an instance of type: {datatype}.
-
- Parameters
- ----------
- t : DataType
- """
- return t.id == lib.Type_NA
-
-
-@doc(is_null, datatype="boolean")
-def is_boolean(t):
- return t.id == lib.Type_BOOL
-
-
-@doc(is_null, datatype="any integer")
-def is_integer(t):
- return t.id in _INTEGER_TYPES
-
-
-@doc(is_null, datatype="signed integer")
-def is_signed_integer(t):
- return t.id in _SIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="unsigned integer")
-def is_unsigned_integer(t):
- return t.id in _UNSIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="int8")
-def is_int8(t):
- return t.id == lib.Type_INT8
-
-
-@doc(is_null, datatype="int16")
-def is_int16(t):
- return t.id == lib.Type_INT16
-
-
-@doc(is_null, datatype="int32")
-def is_int32(t):
- return t.id == lib.Type_INT32
-
-
-@doc(is_null, datatype="int64")
-def is_int64(t):
- return t.id == lib.Type_INT64
-
-
-@doc(is_null, datatype="uint8")
-def is_uint8(t):
- return t.id == lib.Type_UINT8
-
-
-@doc(is_null, datatype="uint16")
-def is_uint16(t):
- return t.id == lib.Type_UINT16
-
-
-@doc(is_null, datatype="uint32")
-def is_uint32(t):
- return t.id == lib.Type_UINT32
-
-
-@doc(is_null, datatype="uint64")
-def is_uint64(t):
- return t.id == lib.Type_UINT64
-
-
-@doc(is_null, datatype="floating point numeric")
-def is_floating(t):
- return t.id in _FLOATING_TYPES
-
-
-@doc(is_null, datatype="float16 (half-precision)")
-def is_float16(t):
- return t.id == lib.Type_HALF_FLOAT
-
-
-@doc(is_null, datatype="float32 (single precision)")
-def is_float32(t):
- return t.id == lib.Type_FLOAT
-
-
-@doc(is_null, datatype="float64 (double precision)")
-def is_float64(t):
- return t.id == lib.Type_DOUBLE
-
-
-@doc(is_null, datatype="list")
-def is_list(t):
- return t.id == lib.Type_LIST
-
-
-@doc(is_null, datatype="large list")
-def is_large_list(t):
- return t.id == lib.Type_LARGE_LIST
-
-
-@doc(is_null, datatype="fixed size list")
-def is_fixed_size_list(t):
- return t.id == lib.Type_FIXED_SIZE_LIST
-
-
-@doc(is_null, datatype="list view")
-def is_list_view(t):
- return t.id == lib.Type_LIST_VIEW
-
-
-@doc(is_null, datatype="large list view")
-def is_large_list_view(t):
- return t.id == lib.Type_LARGE_LIST_VIEW
-
-
-@doc(is_null, datatype="struct")
-def is_struct(t):
- return t.id == lib.Type_STRUCT
-
-
-@doc(is_null, datatype="union")
-def is_union(t):
- return t.id in _UNION_TYPES
-
-
-@doc(is_null, datatype="nested type")
-def is_nested(t):
- return t.id in _NESTED_TYPES
-
-
-@doc(is_null, datatype="run-end encoded")
-def is_run_end_encoded(t):
- return t.id == lib.Type_RUN_END_ENCODED
-
-
-@doc(is_null, datatype="date, time, timestamp or duration")
-def is_temporal(t):
- return t.id in _TEMPORAL_TYPES
-
-
-@doc(is_null, datatype="timestamp")
-def is_timestamp(t):
- return t.id == lib.Type_TIMESTAMP
-
-
-@doc(is_null, datatype="duration")
-def is_duration(t):
- return t.id == lib.Type_DURATION
-
-
-@doc(is_null, datatype="time")
-def is_time(t):
- return t.id in _TIME_TYPES
-
-
-@doc(is_null, datatype="time32")
-def is_time32(t):
- return t.id == lib.Type_TIME32
-
-
-@doc(is_null, datatype="time64")
-def is_time64(t):
- return t.id == lib.Type_TIME64
-
-
-@doc(is_null, datatype="variable-length binary")
-def is_binary(t):
- return t.id == lib.Type_BINARY
-
-
-@doc(is_null, datatype="large variable-length binary")
-def is_large_binary(t):
- return t.id == lib.Type_LARGE_BINARY
-
-
-@doc(method="is_string")
-def is_unicode(t):
- """
- Alias for {method}.
-
- Parameters
- ----------
- t : DataType
- """
- return is_string(t)
-
-
-@doc(is_null, datatype="string (utf8 unicode)")
-def is_string(t):
- return t.id == lib.Type_STRING
-
-
-@doc(is_unicode, method="is_large_string")
-def is_large_unicode(t):
- return is_large_string(t)
-
-
-@doc(is_null, datatype="large string (utf8 unicode)")
-def is_large_string(t):
- return t.id == lib.Type_LARGE_STRING
-
-
-@doc(is_null, datatype="fixed size binary")
-def is_fixed_size_binary(t):
- return t.id == lib.Type_FIXED_SIZE_BINARY
-
-
-@doc(is_null, datatype="variable-length binary view")
-def is_binary_view(t):
- return t.id == lib.Type_BINARY_VIEW
-
-
-@doc(is_null, datatype="variable-length string (utf-8) view")
-def is_string_view(t):
- return t.id == lib.Type_STRING_VIEW
-
-
-@doc(is_null, datatype="date")
-def is_date(t):
- return t.id in _DATE_TYPES
-
-
-@doc(is_null, datatype="date32 (days)")
-def is_date32(t):
- return t.id == lib.Type_DATE32
-
-
-@doc(is_null, datatype="date64 (milliseconds)")
-def is_date64(t):
- return t.id == lib.Type_DATE64
-
-
-@doc(is_null, datatype="map")
-def is_map(t):
- return t.id == lib.Type_MAP
-
-
-@doc(is_null, datatype="decimal")
-def is_decimal(t):
- return t.id in _DECIMAL_TYPES
-
-
-@doc(is_null, datatype="decimal128")
-def is_decimal128(t):
- return t.id == lib.Type_DECIMAL128
-
-
-@doc(is_null, datatype="decimal256")
-def is_decimal256(t):
- return t.id == lib.Type_DECIMAL256
-
-
-@doc(is_null, datatype="dictionary-encoded")
-def is_dictionary(t):
- return t.id == lib.Type_DICTIONARY
-
-
-@doc(is_null, datatype="interval")
-def is_interval(t):
- return t.id == lib.Type_INTERVAL_MONTH_DAY_NANO
-
-
-@doc(is_null, datatype="primitive type")
-def is_primitive(t):
- return lib._is_primitive(t.id)
+ is_float_value,
+ ensure_type,
Review Comment:
fix it.
##########
python/pyarrow/types.py:
##########
@@ -20,295 +20,54 @@
from pyarrow.lib import (is_boolean_value, # noqa
is_integer_value,
- is_float_value)
-
-import pyarrow.lib as lib
-from pyarrow.util import doc
-
-
-_SIGNED_INTEGER_TYPES = {lib.Type_INT8, lib.Type_INT16, lib.Type_INT32,
- lib.Type_INT64}
-_UNSIGNED_INTEGER_TYPES = {lib.Type_UINT8, lib.Type_UINT16, lib.Type_UINT32,
- lib.Type_UINT64}
-_INTEGER_TYPES = _SIGNED_INTEGER_TYPES | _UNSIGNED_INTEGER_TYPES
-_FLOATING_TYPES = {lib.Type_HALF_FLOAT, lib.Type_FLOAT, lib.Type_DOUBLE}
-_DECIMAL_TYPES = {lib.Type_DECIMAL128, lib.Type_DECIMAL256}
-_DATE_TYPES = {lib.Type_DATE32, lib.Type_DATE64}
-_TIME_TYPES = {lib.Type_TIME32, lib.Type_TIME64}
-_INTERVAL_TYPES = {lib.Type_INTERVAL_MONTH_DAY_NANO}
-_TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
- lib.Type_DURATION} | _TIME_TYPES | _DATE_TYPES |
- _INTERVAL_TYPES)
-_UNION_TYPES = {lib.Type_SPARSE_UNION, lib.Type_DENSE_UNION}
-_NESTED_TYPES = {lib.Type_LIST, lib.Type_FIXED_SIZE_LIST, lib.Type_LARGE_LIST,
- lib.Type_LIST_VIEW, lib.Type_LARGE_LIST_VIEW,
- lib.Type_STRUCT, lib.Type_MAP} | _UNION_TYPES
-
-
-@doc(datatype="null")
-def is_null(t):
- """
- Return True if value is an instance of type: {datatype}.
-
- Parameters
- ----------
- t : DataType
- """
- return t.id == lib.Type_NA
-
-
-@doc(is_null, datatype="boolean")
-def is_boolean(t):
- return t.id == lib.Type_BOOL
-
-
-@doc(is_null, datatype="any integer")
-def is_integer(t):
- return t.id in _INTEGER_TYPES
-
-
-@doc(is_null, datatype="signed integer")
-def is_signed_integer(t):
- return t.id in _SIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="unsigned integer")
-def is_unsigned_integer(t):
- return t.id in _UNSIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="int8")
-def is_int8(t):
- return t.id == lib.Type_INT8
-
-
-@doc(is_null, datatype="int16")
-def is_int16(t):
- return t.id == lib.Type_INT16
-
-
-@doc(is_null, datatype="int32")
-def is_int32(t):
- return t.id == lib.Type_INT32
-
-
-@doc(is_null, datatype="int64")
-def is_int64(t):
- return t.id == lib.Type_INT64
-
-
-@doc(is_null, datatype="uint8")
-def is_uint8(t):
- return t.id == lib.Type_UINT8
-
-
-@doc(is_null, datatype="uint16")
-def is_uint16(t):
- return t.id == lib.Type_UINT16
-
-
-@doc(is_null, datatype="uint32")
-def is_uint32(t):
- return t.id == lib.Type_UINT32
-
-
-@doc(is_null, datatype="uint64")
-def is_uint64(t):
- return t.id == lib.Type_UINT64
-
-
-@doc(is_null, datatype="floating point numeric")
-def is_floating(t):
- return t.id in _FLOATING_TYPES
-
-
-@doc(is_null, datatype="float16 (half-precision)")
-def is_float16(t):
- return t.id == lib.Type_HALF_FLOAT
-
-
-@doc(is_null, datatype="float32 (single precision)")
-def is_float32(t):
- return t.id == lib.Type_FLOAT
-
-
-@doc(is_null, datatype="float64 (double precision)")
-def is_float64(t):
- return t.id == lib.Type_DOUBLE
-
-
-@doc(is_null, datatype="list")
-def is_list(t):
- return t.id == lib.Type_LIST
-
-
-@doc(is_null, datatype="large list")
-def is_large_list(t):
- return t.id == lib.Type_LARGE_LIST
-
-
-@doc(is_null, datatype="fixed size list")
-def is_fixed_size_list(t):
- return t.id == lib.Type_FIXED_SIZE_LIST
-
-
-@doc(is_null, datatype="list view")
-def is_list_view(t):
- return t.id == lib.Type_LIST_VIEW
-
-
-@doc(is_null, datatype="large list view")
-def is_large_list_view(t):
- return t.id == lib.Type_LARGE_LIST_VIEW
-
-
-@doc(is_null, datatype="struct")
-def is_struct(t):
- return t.id == lib.Type_STRUCT
-
-
-@doc(is_null, datatype="union")
-def is_union(t):
- return t.id in _UNION_TYPES
-
-
-@doc(is_null, datatype="nested type")
-def is_nested(t):
- return t.id in _NESTED_TYPES
-
-
-@doc(is_null, datatype="run-end encoded")
-def is_run_end_encoded(t):
- return t.id == lib.Type_RUN_END_ENCODED
-
-
-@doc(is_null, datatype="date, time, timestamp or duration")
-def is_temporal(t):
- return t.id in _TEMPORAL_TYPES
-
-
-@doc(is_null, datatype="timestamp")
-def is_timestamp(t):
- return t.id == lib.Type_TIMESTAMP
-
-
-@doc(is_null, datatype="duration")
-def is_duration(t):
- return t.id == lib.Type_DURATION
-
-
-@doc(is_null, datatype="time")
-def is_time(t):
- return t.id in _TIME_TYPES
-
-
-@doc(is_null, datatype="time32")
-def is_time32(t):
- return t.id == lib.Type_TIME32
-
-
-@doc(is_null, datatype="time64")
-def is_time64(t):
- return t.id == lib.Type_TIME64
-
-
-@doc(is_null, datatype="variable-length binary")
-def is_binary(t):
- return t.id == lib.Type_BINARY
-
-
-@doc(is_null, datatype="large variable-length binary")
-def is_large_binary(t):
- return t.id == lib.Type_LARGE_BINARY
-
-
-@doc(method="is_string")
-def is_unicode(t):
- """
- Alias for {method}.
-
- Parameters
- ----------
- t : DataType
- """
- return is_string(t)
-
-
-@doc(is_null, datatype="string (utf8 unicode)")
-def is_string(t):
- return t.id == lib.Type_STRING
-
-
-@doc(is_unicode, method="is_large_string")
-def is_large_unicode(t):
- return is_large_string(t)
-
-
-@doc(is_null, datatype="large string (utf8 unicode)")
-def is_large_string(t):
- return t.id == lib.Type_LARGE_STRING
-
-
-@doc(is_null, datatype="fixed size binary")
-def is_fixed_size_binary(t):
- return t.id == lib.Type_FIXED_SIZE_BINARY
-
-
-@doc(is_null, datatype="variable-length binary view")
-def is_binary_view(t):
- return t.id == lib.Type_BINARY_VIEW
-
-
-@doc(is_null, datatype="variable-length string (utf-8) view")
-def is_string_view(t):
- return t.id == lib.Type_STRING_VIEW
-
-
-@doc(is_null, datatype="date")
-def is_date(t):
- return t.id in _DATE_TYPES
-
-
-@doc(is_null, datatype="date32 (days)")
-def is_date32(t):
- return t.id == lib.Type_DATE32
-
-
-@doc(is_null, datatype="date64 (milliseconds)")
-def is_date64(t):
- return t.id == lib.Type_DATE64
-
-
-@doc(is_null, datatype="map")
-def is_map(t):
- return t.id == lib.Type_MAP
-
-
-@doc(is_null, datatype="decimal")
-def is_decimal(t):
- return t.id in _DECIMAL_TYPES
-
-
-@doc(is_null, datatype="decimal128")
-def is_decimal128(t):
- return t.id == lib.Type_DECIMAL128
-
-
-@doc(is_null, datatype="decimal256")
-def is_decimal256(t):
- return t.id == lib.Type_DECIMAL256
-
-
-@doc(is_null, datatype="dictionary-encoded")
-def is_dictionary(t):
- return t.id == lib.Type_DICTIONARY
-
-
-@doc(is_null, datatype="interval")
-def is_interval(t):
- return t.id == lib.Type_INTERVAL_MONTH_DAY_NANO
-
-
-@doc(is_null, datatype="primitive type")
-def is_primitive(t):
- return lib._is_primitive(t.id)
+ is_float_value,
+ ensure_type,
Review Comment:
I fixed it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1549714892
##########
python/pyarrow/type_traits.pxi:
##########
@@ -0,0 +1,721 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from pyarrow.includes.libarrow cimport (is_integer,
+ is_signed_integer,
+ is_unsigned_integer,
+ is_floating,
+ is_numeric,
+ is_decimal,
+ is_run_end_type,
+ is_primitive,
+ is_base_binary_like,
+ is_binary_like,
+ is_large_binary_like,
+ is_binary,
+ is_string,
+ is_temporal,
+ is_time,
+ is_date,
+ is_interval,
+ is_dictionary,
+ is_fixed_size_binary,
+ is_fixed_width,
+ is_var_length_list,
+ is_list,
+ is_list_like,
+ is_var_length_list_like,
+ is_list_view,
+ is_nested,
+ is_union,
+ bit_width,
+ offset_bit_width)
+
+
+def is_integer_type(data_type):
+ """
+ Check if the data type is an integer type.
+
+ This function checks whether the `data_type` is an integer type, which
+ includes signed and unsigned integers of various bit widths (8, 16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is an integer type before performing
+ operations that are only valid for integers.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check against the set of supported integer types.
+
+ Returns
+ -------
+ bool
+ True if `data_type` is an integer type, False otherwise.
+ """
+ return is_integer(data_type.id)
+
+
+def is_signed_integer_type(data_type):
+ """
+ Check if the data type is a signed integer type.
+
+ This function checks whether the `data_type` is a signed integer type,
+ which includes signed integers of various bit widths (8, 16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is a signed integer type before
+ performing operations that are only valid for signed integers.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is a signed integer type, False otherwise.
+ """
+ return is_signed_integer(data_type.id)
+
+
+def is_unsigned_integer_type(data_type):
+ """
+ Check if the data type is an unsigned integer type.
+
+ This function checks whether the `data_type` is an unsigned integer type,
+ which includes unsigned integers of various bit widths (8, 16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is an unsigned integer type before
+ performing operations that are only valid for unsigned integers.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is an unsigned integer type, False otherwise.
+ """
+ return is_unsigned_integer(data_type.id)
+
+
+def is_floating_type(data_type):
+ """
+ Check if the data type is a floating type.
+
+ This function checks whether the `data_type` is a floating type, which includes
+ floating point numbers of various bit widths (16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is a floating type before performing
+ operations that are only valid for floating point numbers.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is a floating type, False otherwise.
+ """
+ return is_floating(data_type.id)
+
+
+def is_numeric_type(data_type):
+ """
+ Check if the data type is a numeric type.
+
+ This function checks whether the `data_type` is a numeric type, which includes
+ integers and floating point numbers with specific bit widths. Integer types
+ include signed and unsigned integers of various bit widths (8, 16, 32, 64 bits),
+ while floating point types include floating point numbers of various bit widths
+ (16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is a numeric type before performing
+ operations that are only valid for numeric types.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is a numeric type, False otherwise.
+ """
+ return is_numeric(data_type.id)
+
+
+def is_decimal_type(data_type):
+ """
+ Check if the data type is a decimal type.
+
+ This function checks whether the `data_type` is a decimal type, which includes
+ fixed-point decimal numbers with specific precision and scale.
+
+ Useful for ensuring that a given data type is a decimal type before performing
+ operations that are only valid for decimal numbers.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is a decimal type, False otherwise.
+ """
+ return is_decimal(data_type.id)
+
+
+def is_run_end_type_py(data_type):
+ """
+ Check if the data type is a run end type.
+
+ This function checks whether the `data_type` is a run end type, which includes
+ integers of various bit widths (16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is a run end type before performing
+ operations that are only valid for run end types.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is a run end type, False otherwise.
+ """
+ return is_run_end_type(data_type.id)
+
+
+def is_primitive_type(data_type):
+ """
+ Check if the data type is a primitive type.
+
+ This function checks whether the `data_type` is a primitive type, which includes
+ integers, floating point numbers, dates (days since the UNIX epoch and milliseconds
+ since the UNIX epoch), times (seconds and milliseconds since midnight),
+ timestamp (milliseconds since the UNIX epoch), and duration (elapsed time in
+ seconds, milliseconds, microseconds, and nanoseconds), and intervals (months,
Review Comment:
I updated docstring as you mentioned
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1562440848
##########
python/pyarrow/tests/test_types.py:
##########
@@ -94,39 +93,39 @@ def get_many_types():
def test_is_boolean():
- assert types.is_boolean(pa.bool_())
- assert not types.is_boolean(pa.int8())
+ assert pa.types.is_boolean(pa.bool_())
Review Comment:
You are right. I replaced `pa.types` to `types.`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2114557356
Thank you for the clarification @danepitkin! I have also misunderstood the issue and guided @llama90 in wrong directions, very sorry about that! I hope you are still willing to finish this and that the clarification from Dane helps?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "danepitkin (via GitHub)" <gi...@apache.org>.
danepitkin commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2113062919
Hi @llama90 , I filed the original issue. Your PR is reimplementing too many things. This issue was originally filed due to this comment: https://github.com/apache/arrow/pull/40265/files#r1505826814
To help clarify, we don't want to reimplement all of the type checks. Instead, we want to investigate if we can replace these python-defined vars https://github.com/apache/arrow/blob/e1de9c52d5a60b2e2a314b8589170467fe36415d/python/pyarrow/types.py#L29-L46 with checks that might already exist in C++. For example, can we replace this line https://github.com/apache/arrow/blob/e1de9c52d5a60b2e2a314b8589170467fe36415d/python/pyarrow/types.py#L177 with an existing Arrow C++ function that we could expose via cython.
Let me know if that helps.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2038914655
@pitrou mind giving one more look before I merge?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1536793845
##########
python/pyarrow/types.py:
##########
@@ -20,29 +20,47 @@
from pyarrow.lib import (is_boolean_value, # noqa
is_integer_value,
- is_float_value)
+ is_float_value,
+ is_integer_type,
+ is_signed_integer_type,
+ is_unsigned_integer_type,
+ is_floating_type,
+ is_numeric_type,
+ is_decimal_type,
+ is_run_end_type_py,
+ is_primitive_type,
+ is_base_binary_like_type,
+ is_binary_like_type,
+ is_large_binary_like_type,
+ is_binary_type,
+ is_string_type,
+ is_temporal_type,
+ is_time_type,
+ is_date_type,
+ is_interval_type,
+ is_dictionary_type,
+ is_fixed_size_binary_type,
+ is_fixed_width_type,
+ is_var_length_list_type,
+ is_list_type,
+ is_list_like_type,
+ is_var_length_list_like_type,
+ is_list_view_type,
+ is_nested_type,
+ is_union_type,
+ is_bit_width_type,
+ is_offset_bit_width_type)
import pyarrow.lib as lib
from pyarrow.util import doc
-_SIGNED_INTEGER_TYPES = {lib.Type_INT8, lib.Type_INT16, lib.Type_INT32,
- lib.Type_INT64}
-_UNSIGNED_INTEGER_TYPES = {lib.Type_UINT8, lib.Type_UINT16, lib.Type_UINT32,
- lib.Type_UINT64}
-_INTEGER_TYPES = _SIGNED_INTEGER_TYPES | _UNSIGNED_INTEGER_TYPES
-_FLOATING_TYPES = {lib.Type_HALF_FLOAT, lib.Type_FLOAT, lib.Type_DOUBLE}
-_DECIMAL_TYPES = {lib.Type_DECIMAL128, lib.Type_DECIMAL256}
_DATE_TYPES = {lib.Type_DATE32, lib.Type_DATE64}
_TIME_TYPES = {lib.Type_TIME32, lib.Type_TIME64}
_INTERVAL_TYPES = {lib.Type_INTERVAL_MONTH_DAY_NANO}
_TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
Review Comment:
There are types among these that cannot be simply replaced.
https://github.com/apache/arrow/blob/6aa6f859bf1aee7cea65e8ab8a85fe6c0119a0ae/cpp/src/arrow/type_traits.h#L1207-L1219
As you can see, the types being handled are different.
##########
python/pyarrow/types.py:
##########
@@ -64,17 +82,17 @@ def is_boolean(t):
@doc(is_null, datatype="any integer")
def is_integer(t):
- return t.id in _INTEGER_TYPES
+ return is_integer_type(t)
@doc(is_null, datatype="signed integer")
def is_signed_integer(t):
- return t.id in _SIGNED_INTEGER_TYPES
+ return is_signed_integer_type(t)
@doc(is_null, datatype="unsigned integer")
def is_unsigned_integer(t):
- return t.id in _UNSIGNED_INTEGER_TYPES
+ return is_unsigned_integer_type(t)
@doc(is_null, datatype="int8")
Review Comment:
There are no functions exposed on a one-to-one basis in `type_traits.h` for these types.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1537407769
##########
python/pyarrow/type_traits.pxi:
##########
@@ -0,0 +1,394 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from pyarrow.includes.libarrow cimport (is_integer,
+ is_signed_integer,
+ is_unsigned_integer,
+ is_floating,
+ is_numeric,
+ is_decimal,
+ is_run_end_type,
+ is_primitive,
+ is_base_binary_like,
+ is_binary_like,
+ is_large_binary_like,
+ is_binary,
+ is_string,
+ is_temporal,
+ is_time,
+ is_date,
+ is_interval,
+ is_dictionary,
+ is_fixed_size_binary,
+ is_fixed_width,
+ is_var_length_list,
+ is_list,
+ is_list_like,
+ is_var_length_list_like,
+ is_list_view,
+ is_nested,
+ is_union,
+ bit_width,
+ offset_bit_width)
+
+
+def is_integer_type(data_type):
+ """
+ Check if the data type is an integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_integer(data_type.id)
+
+
+def is_signed_integer_type(data_type):
+ """
+ Check if the data type is a signed integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_signed_integer(data_type.id)
+
+
+def is_unsigned_integer_type(data_type):
+ """
+ Check if the data type is an unsigned integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_unsigned_integer(data_type.id)
+
+
+def is_floating_type(data_type):
+ """
+ Check if the data type is a floating type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_floating(data_type.id)
+
+
+def is_numeric_type(data_type):
+ """
+ Check if the data type is a numeric type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_numeric(data_type.id)
+
+
+def is_decimal_type(data_type):
+ """
+ Check if the data type is a decimal type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_decimal(data_type.id)
+
+
+def is_run_end_type_py(data_type):
+ """
+ Check if the data type is a run end type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_run_end_type(data_type.id)
+
+
+def is_primitive_type(data_type):
+ """
+ Check if the data type is a primitive type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_primitive(data_type.id)
+
+
+def is_base_binary_like_type(data_type):
+ """
+ Check if the data type is a base_binary_like type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_base_binary_like(data_type.id)
+
+
+def is_binary_like_type(data_type):
+ """
+ Check if the data type is a _binary_like type.
Review Comment:
These docstrings are not useful if they merely repeat what the function name says. You should explain what a "_binary_like" type is, because the reader probably doesn't know.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2017731569
:warning: GitHub issue #40282 **has been automatically assigned in GitHub** to PR creator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2114625768
I haven’t reviewed it in detail yet, but I will consider feedback and proceed accordingly. Thank you!!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 closed pull request #40761: GH-40282: [Python] Use C++ type traits
URL: https://github.com/apache/arrow/pull/40761
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1551705226
##########
python/pyarrow/type_traits.pxi:
##########
@@ -0,0 +1,583 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from pyarrow.includes.libarrow cimport (is_integer,
+ is_signed_integer,
+ is_unsigned_integer,
+ is_floating,
+ is_numeric,
+ is_decimal,
+ is_run_end_type,
+ is_primitive,
+ is_base_binary_like,
+ is_binary_like,
+ is_large_binary_like,
+ is_binary,
+ is_string,
+ is_temporal,
+ is_time,
+ is_date,
+ is_interval,
+ is_dictionary,
+ is_fixed_size_binary,
+ is_fixed_width,
+ is_var_length_list,
+ is_list,
+ is_list_like,
+ is_var_length_list_like,
+ is_list_view,
+ is_nested,
+ is_union,
+ bit_width,
+ offset_bit_width)
+
+
Review Comment:
```suggestion
# These functions are simply a redirect, the official APIs are in pyarrow.types.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1553224991
##########
python/pyarrow/type_traits.pxi:
##########
@@ -0,0 +1,585 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from pyarrow.includes.libarrow cimport (is_integer,
+ is_signed_integer,
+ is_unsigned_integer,
+ is_floating,
+ is_numeric,
+ is_decimal,
+ is_run_end_type,
+ is_primitive,
+ is_base_binary_like,
+ is_binary_like,
+ is_large_binary_like,
+ is_binary,
+ is_string,
+ is_temporal,
+ is_time,
+ is_date,
+ is_interval,
+ is_dictionary,
+ is_fixed_size_binary,
+ is_fixed_width,
+ is_var_length_list,
+ is_list,
+ is_list_like,
+ is_var_length_list_like,
+ is_list_view,
+ is_nested,
+ is_union,
+ bit_width,
+ offset_bit_width)
+
+# These functions are simply a redirect, the official APIs are in pyarrow.types.
Review Comment:
This is overly complicated. Why maintain these wrappers and their docstrings? You can instead define the official APIs directly in Cython code (for example in `types.pxi`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: Use C++ type traits [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2016442693
:warning: GitHub issue #40282 **has been automatically assigned in GitHub** to PR creator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2024781808
I've updated the docstrings based on the review and made adjustments to ensure that existing functions work using the functions in `type_traits.h` that are already available.
I understand that pyarrow has a wide user base, and to avoid breaking compatibility, I've made sure that functions in the form of `is_${type}` can still operate as intended. (If I'm mistaken, please let me know.)
Additionally, I plan to create a new issue to address types such as `NA`, `BINARY_VIEW`, `STRING_VIEW`, `FIXED_SIZE_LIST`, `STRUCT`, and `RUN_END_ENCODED`, which have the following considerations:
- `NA`, `BINARY_VIEW`, `STRING_VIEW` require C++ implementation in `type_traits.h`.
- While there are functions to check `FIXED_SIZE_LIST`, `STRUCT`, `RUN_END_ENCODED` types in `type_traits.h`, they might not be directly usable.
This requires further consideration, and I intend to proceed with a new issue for it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1542381779
##########
python/pyarrow/type_traits.pxi:
##########
@@ -0,0 +1,394 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from pyarrow.includes.libarrow cimport (is_integer,
+ is_signed_integer,
+ is_unsigned_integer,
+ is_floating,
+ is_numeric,
+ is_decimal,
+ is_run_end_type,
+ is_primitive,
+ is_base_binary_like,
+ is_binary_like,
+ is_large_binary_like,
+ is_binary,
+ is_string,
+ is_temporal,
+ is_time,
+ is_date,
+ is_interval,
+ is_dictionary,
+ is_fixed_size_binary,
+ is_fixed_width,
+ is_var_length_list,
+ is_list,
+ is_list_like,
+ is_var_length_list_like,
+ is_list_view,
+ is_nested,
+ is_union,
+ bit_width,
+ offset_bit_width)
+
+
+def is_integer_type(data_type):
+ """
+ Check if the data type is an integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_integer(data_type.id)
+
+
+def is_signed_integer_type(data_type):
+ """
+ Check if the data type is a signed integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_signed_integer(data_type.id)
+
+
+def is_unsigned_integer_type(data_type):
+ """
+ Check if the data type is an unsigned integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_unsigned_integer(data_type.id)
+
+
+def is_floating_type(data_type):
+ """
+ Check if the data type is a floating type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_floating(data_type.id)
+
+
+def is_numeric_type(data_type):
+ """
+ Check if the data type is a numeric type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_numeric(data_type.id)
+
+
+def is_decimal_type(data_type):
+ """
+ Check if the data type is a decimal type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_decimal(data_type.id)
+
+
+def is_run_end_type_py(data_type):
+ """
+ Check if the data type is a run end type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_run_end_type(data_type.id)
+
+
+def is_primitive_type(data_type):
+ """
+ Check if the data type is a primitive type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_primitive(data_type.id)
+
+
+def is_base_binary_like_type(data_type):
+ """
+ Check if the data type is a base_binary_like type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_base_binary_like(data_type.id)
+
+
+def is_binary_like_type(data_type):
+ """
+ Check if the data type is a _binary_like type.
Review Comment:
I have enhanced the content.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1590675494
##########
python/pyarrow/types.py:
##########
@@ -20,295 +20,54 @@
from pyarrow.lib import (is_boolean_value, # noqa
is_integer_value,
- is_float_value)
-
-import pyarrow.lib as lib
-from pyarrow.util import doc
-
-
-_SIGNED_INTEGER_TYPES = {lib.Type_INT8, lib.Type_INT16, lib.Type_INT32,
- lib.Type_INT64}
-_UNSIGNED_INTEGER_TYPES = {lib.Type_UINT8, lib.Type_UINT16, lib.Type_UINT32,
- lib.Type_UINT64}
-_INTEGER_TYPES = _SIGNED_INTEGER_TYPES | _UNSIGNED_INTEGER_TYPES
-_FLOATING_TYPES = {lib.Type_HALF_FLOAT, lib.Type_FLOAT, lib.Type_DOUBLE}
-_DECIMAL_TYPES = {lib.Type_DECIMAL128, lib.Type_DECIMAL256}
-_DATE_TYPES = {lib.Type_DATE32, lib.Type_DATE64}
-_TIME_TYPES = {lib.Type_TIME32, lib.Type_TIME64}
-_INTERVAL_TYPES = {lib.Type_INTERVAL_MONTH_DAY_NANO}
-_TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
- lib.Type_DURATION} | _TIME_TYPES | _DATE_TYPES |
- _INTERVAL_TYPES)
-_UNION_TYPES = {lib.Type_SPARSE_UNION, lib.Type_DENSE_UNION}
-_NESTED_TYPES = {lib.Type_LIST, lib.Type_FIXED_SIZE_LIST, lib.Type_LARGE_LIST,
- lib.Type_LIST_VIEW, lib.Type_LARGE_LIST_VIEW,
- lib.Type_STRUCT, lib.Type_MAP} | _UNION_TYPES
-
-
-@doc(datatype="null")
-def is_null(t):
- """
- Return True if value is an instance of type: {datatype}.
-
- Parameters
- ----------
- t : DataType
- """
- return t.id == lib.Type_NA
-
-
-@doc(is_null, datatype="boolean")
-def is_boolean(t):
- return t.id == lib.Type_BOOL
-
-
-@doc(is_null, datatype="any integer")
-def is_integer(t):
- return t.id in _INTEGER_TYPES
-
-
-@doc(is_null, datatype="signed integer")
-def is_signed_integer(t):
- return t.id in _SIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="unsigned integer")
-def is_unsigned_integer(t):
- return t.id in _UNSIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="int8")
-def is_int8(t):
- return t.id == lib.Type_INT8
-
-
-@doc(is_null, datatype="int16")
-def is_int16(t):
- return t.id == lib.Type_INT16
-
-
-@doc(is_null, datatype="int32")
-def is_int32(t):
- return t.id == lib.Type_INT32
-
-
-@doc(is_null, datatype="int64")
-def is_int64(t):
- return t.id == lib.Type_INT64
-
-
-@doc(is_null, datatype="uint8")
-def is_uint8(t):
- return t.id == lib.Type_UINT8
-
-
-@doc(is_null, datatype="uint16")
-def is_uint16(t):
- return t.id == lib.Type_UINT16
-
-
-@doc(is_null, datatype="uint32")
-def is_uint32(t):
- return t.id == lib.Type_UINT32
-
-
-@doc(is_null, datatype="uint64")
-def is_uint64(t):
- return t.id == lib.Type_UINT64
-
-
-@doc(is_null, datatype="floating point numeric")
-def is_floating(t):
- return t.id in _FLOATING_TYPES
-
-
-@doc(is_null, datatype="float16 (half-precision)")
-def is_float16(t):
- return t.id == lib.Type_HALF_FLOAT
-
-
-@doc(is_null, datatype="float32 (single precision)")
-def is_float32(t):
- return t.id == lib.Type_FLOAT
-
-
-@doc(is_null, datatype="float64 (double precision)")
-def is_float64(t):
- return t.id == lib.Type_DOUBLE
-
-
-@doc(is_null, datatype="list")
-def is_list(t):
- return t.id == lib.Type_LIST
-
-
-@doc(is_null, datatype="large list")
-def is_large_list(t):
- return t.id == lib.Type_LARGE_LIST
-
-
-@doc(is_null, datatype="fixed size list")
-def is_fixed_size_list(t):
- return t.id == lib.Type_FIXED_SIZE_LIST
-
-
-@doc(is_null, datatype="list view")
-def is_list_view(t):
- return t.id == lib.Type_LIST_VIEW
-
-
-@doc(is_null, datatype="large list view")
-def is_large_list_view(t):
- return t.id == lib.Type_LARGE_LIST_VIEW
-
-
-@doc(is_null, datatype="struct")
-def is_struct(t):
- return t.id == lib.Type_STRUCT
-
-
-@doc(is_null, datatype="union")
-def is_union(t):
- return t.id in _UNION_TYPES
-
-
-@doc(is_null, datatype="nested type")
-def is_nested(t):
- return t.id in _NESTED_TYPES
-
-
-@doc(is_null, datatype="run-end encoded")
-def is_run_end_encoded(t):
- return t.id == lib.Type_RUN_END_ENCODED
-
-
-@doc(is_null, datatype="date, time, timestamp or duration")
-def is_temporal(t):
- return t.id in _TEMPORAL_TYPES
-
-
-@doc(is_null, datatype="timestamp")
-def is_timestamp(t):
- return t.id == lib.Type_TIMESTAMP
-
-
-@doc(is_null, datatype="duration")
-def is_duration(t):
- return t.id == lib.Type_DURATION
-
-
-@doc(is_null, datatype="time")
-def is_time(t):
- return t.id in _TIME_TYPES
-
-
-@doc(is_null, datatype="time32")
-def is_time32(t):
- return t.id == lib.Type_TIME32
-
-
-@doc(is_null, datatype="time64")
-def is_time64(t):
- return t.id == lib.Type_TIME64
-
-
-@doc(is_null, datatype="variable-length binary")
-def is_binary(t):
- return t.id == lib.Type_BINARY
-
-
-@doc(is_null, datatype="large variable-length binary")
-def is_large_binary(t):
- return t.id == lib.Type_LARGE_BINARY
-
-
-@doc(method="is_string")
-def is_unicode(t):
- """
- Alias for {method}.
-
- Parameters
- ----------
- t : DataType
- """
- return is_string(t)
-
-
-@doc(is_null, datatype="string (utf8 unicode)")
-def is_string(t):
- return t.id == lib.Type_STRING
-
-
-@doc(is_unicode, method="is_large_string")
-def is_large_unicode(t):
- return is_large_string(t)
-
-
-@doc(is_null, datatype="large string (utf8 unicode)")
-def is_large_string(t):
- return t.id == lib.Type_LARGE_STRING
-
-
-@doc(is_null, datatype="fixed size binary")
-def is_fixed_size_binary(t):
- return t.id == lib.Type_FIXED_SIZE_BINARY
-
-
-@doc(is_null, datatype="variable-length binary view")
-def is_binary_view(t):
- return t.id == lib.Type_BINARY_VIEW
-
-
-@doc(is_null, datatype="variable-length string (utf-8) view")
-def is_string_view(t):
- return t.id == lib.Type_STRING_VIEW
-
-
-@doc(is_null, datatype="date")
-def is_date(t):
- return t.id in _DATE_TYPES
-
-
-@doc(is_null, datatype="date32 (days)")
-def is_date32(t):
- return t.id == lib.Type_DATE32
-
-
-@doc(is_null, datatype="date64 (milliseconds)")
-def is_date64(t):
- return t.id == lib.Type_DATE64
-
-
-@doc(is_null, datatype="map")
-def is_map(t):
- return t.id == lib.Type_MAP
-
-
-@doc(is_null, datatype="decimal")
-def is_decimal(t):
- return t.id in _DECIMAL_TYPES
-
-
-@doc(is_null, datatype="decimal128")
-def is_decimal128(t):
- return t.id == lib.Type_DECIMAL128
-
-
-@doc(is_null, datatype="decimal256")
-def is_decimal256(t):
- return t.id == lib.Type_DECIMAL256
-
-
-@doc(is_null, datatype="dictionary-encoded")
-def is_dictionary(t):
- return t.id == lib.Type_DICTIONARY
-
-
-@doc(is_null, datatype="interval")
-def is_interval(t):
- return t.id == lib.Type_INTERVAL_MONTH_DAY_NANO
-
-
-@doc(is_null, datatype="primitive type")
-def is_primitive(t):
- return lib._is_primitive(t.id)
+ is_float_value,
+ ensure_type,
+ _is_integer as is_integer,
Review Comment:
Sorry for late response @llama90!
Hm, I have to agree that the current import in _types.py_ is not optimal but looking at how it is currently done for `is_primitive` my first instinct was to mimic that:
https://github.com/apache/arrow/blob/4cf44b4bc3ab053b03c937d3327d43c105790462/python/pyarrow/includes/libarrow.pxd#L175
https://github.com/apache/arrow/blob/4cf44b4bc3ab053b03c937d3327d43c105790462/python/pyarrow/types.pxi#L145-L147
https://github.com/apache/arrow/blob/4cf44b4bc3ab053b03c937d3327d43c105790462/python/pyarrow/types.py#L312-L314
and so I am also unsure how to optimise and what @pitrou had in mind.
One thing you could try is to rename C++ functions on Cython import, example:
https://github.com/apache/arrow/blob/4cf44b4bc3ab053b03c937d3327d43c105790462/python/pyarrow/includes/common.pxd#L116
Not sure if it will cause any issues later in Python though.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2095417100
Hi @llama90, added a comment - hope it will help to get this PR moving forward.
The code also needs a rebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "felipecrv (via GitHub)" <gi...@apache.org>.
felipecrv commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2118215934
> Aha... I see that maintaining both C++ and Python code identically may complicate maintenance.
To make what I posted last night more concrete, an example: the predicate `is_list_like` can't consider list-views "list-like" because list-views were added after the `is_list_like` predicate existed. We ended up in a situation where `fixed_size_list` and `map` are list-like, but list-views aren't. It's the right thing to do to not break existing code, but is very confusing to newcomers.
We shouldn't re-use the same names on the Python side with different meaning from what we have on the C++ side, but if backwards-compatibility issues aren't the same on the Python side, we could do better.
<img width="1064" alt="Screenshot 2024-05-17 at 15 59 02" src="https://github.com/apache/arrow/assets/207795/9ea5ab41-ba56-4c3f-862e-dc56db85a3b7">
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2041033310
And the failure at [link](https://github.com/apache/arrow/actions/runs/8579651215/job/23514860438?pr=40761) seems to be unrelated to my code changes. The same test passes without any issues locally. It's quite puzzling...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1557963435
##########
python/pyarrow/types.pxi:
##########
@@ -5401,6 +5428,1069 @@ def is_float_value(object obj):
return IsPyFloat(obj)
+def _is_integer(data_type):
+ """
+ This function checks whether the `data_type` is an integer type, which
+ includes signed and unsigned integers of various bit widths (8, 16, 32, 64 bits).
Review Comment:
We can probably keep the original wording, which is more terse and as informative:
```suggestion
Return whether the `data_type` is an integer type.
```
##########
python/pyarrow/tests/test_types.py:
##########
@@ -94,39 +93,39 @@ def get_many_types():
def test_is_boolean():
- assert types.is_boolean(pa.bool_())
- assert not types.is_boolean(pa.int8())
+ assert pa.types.is_boolean(pa.bool_())
Review Comment:
Are these changes necessary for some reason? They are not problematic, but they don't seem required either.
##########
python/pyarrow/types.py:
##########
@@ -20,295 +20,54 @@
from pyarrow.lib import (is_boolean_value, # noqa
is_integer_value,
- is_float_value)
-
-import pyarrow.lib as lib
-from pyarrow.util import doc
-
-
-_SIGNED_INTEGER_TYPES = {lib.Type_INT8, lib.Type_INT16, lib.Type_INT32,
- lib.Type_INT64}
-_UNSIGNED_INTEGER_TYPES = {lib.Type_UINT8, lib.Type_UINT16, lib.Type_UINT32,
- lib.Type_UINT64}
-_INTEGER_TYPES = _SIGNED_INTEGER_TYPES | _UNSIGNED_INTEGER_TYPES
-_FLOATING_TYPES = {lib.Type_HALF_FLOAT, lib.Type_FLOAT, lib.Type_DOUBLE}
-_DECIMAL_TYPES = {lib.Type_DECIMAL128, lib.Type_DECIMAL256}
-_DATE_TYPES = {lib.Type_DATE32, lib.Type_DATE64}
-_TIME_TYPES = {lib.Type_TIME32, lib.Type_TIME64}
-_INTERVAL_TYPES = {lib.Type_INTERVAL_MONTH_DAY_NANO}
-_TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
- lib.Type_DURATION} | _TIME_TYPES | _DATE_TYPES |
- _INTERVAL_TYPES)
-_UNION_TYPES = {lib.Type_SPARSE_UNION, lib.Type_DENSE_UNION}
-_NESTED_TYPES = {lib.Type_LIST, lib.Type_FIXED_SIZE_LIST, lib.Type_LARGE_LIST,
- lib.Type_LIST_VIEW, lib.Type_LARGE_LIST_VIEW,
- lib.Type_STRUCT, lib.Type_MAP} | _UNION_TYPES
-
-
-@doc(datatype="null")
-def is_null(t):
- """
- Return True if value is an instance of type: {datatype}.
-
- Parameters
- ----------
- t : DataType
- """
- return t.id == lib.Type_NA
-
-
-@doc(is_null, datatype="boolean")
-def is_boolean(t):
- return t.id == lib.Type_BOOL
-
-
-@doc(is_null, datatype="any integer")
-def is_integer(t):
- return t.id in _INTEGER_TYPES
-
-
-@doc(is_null, datatype="signed integer")
-def is_signed_integer(t):
- return t.id in _SIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="unsigned integer")
-def is_unsigned_integer(t):
- return t.id in _UNSIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="int8")
-def is_int8(t):
- return t.id == lib.Type_INT8
-
-
-@doc(is_null, datatype="int16")
-def is_int16(t):
- return t.id == lib.Type_INT16
-
-
-@doc(is_null, datatype="int32")
-def is_int32(t):
- return t.id == lib.Type_INT32
-
-
-@doc(is_null, datatype="int64")
-def is_int64(t):
- return t.id == lib.Type_INT64
-
-
-@doc(is_null, datatype="uint8")
-def is_uint8(t):
- return t.id == lib.Type_UINT8
-
-
-@doc(is_null, datatype="uint16")
-def is_uint16(t):
- return t.id == lib.Type_UINT16
-
-
-@doc(is_null, datatype="uint32")
-def is_uint32(t):
- return t.id == lib.Type_UINT32
-
-
-@doc(is_null, datatype="uint64")
-def is_uint64(t):
- return t.id == lib.Type_UINT64
-
-
-@doc(is_null, datatype="floating point numeric")
-def is_floating(t):
- return t.id in _FLOATING_TYPES
-
-
-@doc(is_null, datatype="float16 (half-precision)")
-def is_float16(t):
- return t.id == lib.Type_HALF_FLOAT
-
-
-@doc(is_null, datatype="float32 (single precision)")
-def is_float32(t):
- return t.id == lib.Type_FLOAT
-
-
-@doc(is_null, datatype="float64 (double precision)")
-def is_float64(t):
- return t.id == lib.Type_DOUBLE
-
-
-@doc(is_null, datatype="list")
-def is_list(t):
- return t.id == lib.Type_LIST
-
-
-@doc(is_null, datatype="large list")
-def is_large_list(t):
- return t.id == lib.Type_LARGE_LIST
-
-
-@doc(is_null, datatype="fixed size list")
-def is_fixed_size_list(t):
- return t.id == lib.Type_FIXED_SIZE_LIST
-
-
-@doc(is_null, datatype="list view")
-def is_list_view(t):
- return t.id == lib.Type_LIST_VIEW
-
-
-@doc(is_null, datatype="large list view")
-def is_large_list_view(t):
- return t.id == lib.Type_LARGE_LIST_VIEW
-
-
-@doc(is_null, datatype="struct")
-def is_struct(t):
- return t.id == lib.Type_STRUCT
-
-
-@doc(is_null, datatype="union")
-def is_union(t):
- return t.id in _UNION_TYPES
-
-
-@doc(is_null, datatype="nested type")
-def is_nested(t):
- return t.id in _NESTED_TYPES
-
-
-@doc(is_null, datatype="run-end encoded")
-def is_run_end_encoded(t):
- return t.id == lib.Type_RUN_END_ENCODED
-
-
-@doc(is_null, datatype="date, time, timestamp or duration")
-def is_temporal(t):
- return t.id in _TEMPORAL_TYPES
-
-
-@doc(is_null, datatype="timestamp")
-def is_timestamp(t):
- return t.id == lib.Type_TIMESTAMP
-
-
-@doc(is_null, datatype="duration")
-def is_duration(t):
- return t.id == lib.Type_DURATION
-
-
-@doc(is_null, datatype="time")
-def is_time(t):
- return t.id in _TIME_TYPES
-
-
-@doc(is_null, datatype="time32")
-def is_time32(t):
- return t.id == lib.Type_TIME32
-
-
-@doc(is_null, datatype="time64")
-def is_time64(t):
- return t.id == lib.Type_TIME64
-
-
-@doc(is_null, datatype="variable-length binary")
-def is_binary(t):
- return t.id == lib.Type_BINARY
-
-
-@doc(is_null, datatype="large variable-length binary")
-def is_large_binary(t):
- return t.id == lib.Type_LARGE_BINARY
-
-
-@doc(method="is_string")
-def is_unicode(t):
- """
- Alias for {method}.
-
- Parameters
- ----------
- t : DataType
- """
- return is_string(t)
-
-
-@doc(is_null, datatype="string (utf8 unicode)")
-def is_string(t):
- return t.id == lib.Type_STRING
-
-
-@doc(is_unicode, method="is_large_string")
-def is_large_unicode(t):
- return is_large_string(t)
-
-
-@doc(is_null, datatype="large string (utf8 unicode)")
-def is_large_string(t):
- return t.id == lib.Type_LARGE_STRING
-
-
-@doc(is_null, datatype="fixed size binary")
-def is_fixed_size_binary(t):
- return t.id == lib.Type_FIXED_SIZE_BINARY
-
-
-@doc(is_null, datatype="variable-length binary view")
-def is_binary_view(t):
- return t.id == lib.Type_BINARY_VIEW
-
-
-@doc(is_null, datatype="variable-length string (utf-8) view")
-def is_string_view(t):
- return t.id == lib.Type_STRING_VIEW
-
-
-@doc(is_null, datatype="date")
-def is_date(t):
- return t.id in _DATE_TYPES
-
-
-@doc(is_null, datatype="date32 (days)")
-def is_date32(t):
- return t.id == lib.Type_DATE32
-
-
-@doc(is_null, datatype="date64 (milliseconds)")
-def is_date64(t):
- return t.id == lib.Type_DATE64
-
-
-@doc(is_null, datatype="map")
-def is_map(t):
- return t.id == lib.Type_MAP
-
-
-@doc(is_null, datatype="decimal")
-def is_decimal(t):
- return t.id in _DECIMAL_TYPES
-
-
-@doc(is_null, datatype="decimal128")
-def is_decimal128(t):
- return t.id == lib.Type_DECIMAL128
-
-
-@doc(is_null, datatype="decimal256")
-def is_decimal256(t):
- return t.id == lib.Type_DECIMAL256
-
-
-@doc(is_null, datatype="dictionary-encoded")
-def is_dictionary(t):
- return t.id == lib.Type_DICTIONARY
-
-
-@doc(is_null, datatype="interval")
-def is_interval(t):
- return t.id == lib.Type_INTERVAL_MONTH_DAY_NANO
-
-
-@doc(is_null, datatype="primitive type")
-def is_primitive(t):
- return lib._is_primitive(t.id)
+ is_float_value,
+ ensure_type,
+ _is_integer as is_integer,
Review Comment:
You can simply define those without a leading underscore in `types.pxi`. This will simplify the imports.
##########
python/pyarrow/types.py:
##########
@@ -20,295 +20,54 @@
from pyarrow.lib import (is_boolean_value, # noqa
is_integer_value,
- is_float_value)
-
-import pyarrow.lib as lib
-from pyarrow.util import doc
-
-
-_SIGNED_INTEGER_TYPES = {lib.Type_INT8, lib.Type_INT16, lib.Type_INT32,
- lib.Type_INT64}
-_UNSIGNED_INTEGER_TYPES = {lib.Type_UINT8, lib.Type_UINT16, lib.Type_UINT32,
- lib.Type_UINT64}
-_INTEGER_TYPES = _SIGNED_INTEGER_TYPES | _UNSIGNED_INTEGER_TYPES
-_FLOATING_TYPES = {lib.Type_HALF_FLOAT, lib.Type_FLOAT, lib.Type_DOUBLE}
-_DECIMAL_TYPES = {lib.Type_DECIMAL128, lib.Type_DECIMAL256}
-_DATE_TYPES = {lib.Type_DATE32, lib.Type_DATE64}
-_TIME_TYPES = {lib.Type_TIME32, lib.Type_TIME64}
-_INTERVAL_TYPES = {lib.Type_INTERVAL_MONTH_DAY_NANO}
-_TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
- lib.Type_DURATION} | _TIME_TYPES | _DATE_TYPES |
- _INTERVAL_TYPES)
-_UNION_TYPES = {lib.Type_SPARSE_UNION, lib.Type_DENSE_UNION}
-_NESTED_TYPES = {lib.Type_LIST, lib.Type_FIXED_SIZE_LIST, lib.Type_LARGE_LIST,
- lib.Type_LIST_VIEW, lib.Type_LARGE_LIST_VIEW,
- lib.Type_STRUCT, lib.Type_MAP} | _UNION_TYPES
-
-
-@doc(datatype="null")
-def is_null(t):
- """
- Return True if value is an instance of type: {datatype}.
-
- Parameters
- ----------
- t : DataType
- """
- return t.id == lib.Type_NA
-
-
-@doc(is_null, datatype="boolean")
-def is_boolean(t):
- return t.id == lib.Type_BOOL
-
-
-@doc(is_null, datatype="any integer")
-def is_integer(t):
- return t.id in _INTEGER_TYPES
-
-
-@doc(is_null, datatype="signed integer")
-def is_signed_integer(t):
- return t.id in _SIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="unsigned integer")
-def is_unsigned_integer(t):
- return t.id in _UNSIGNED_INTEGER_TYPES
-
-
-@doc(is_null, datatype="int8")
-def is_int8(t):
- return t.id == lib.Type_INT8
-
-
-@doc(is_null, datatype="int16")
-def is_int16(t):
- return t.id == lib.Type_INT16
-
-
-@doc(is_null, datatype="int32")
-def is_int32(t):
- return t.id == lib.Type_INT32
-
-
-@doc(is_null, datatype="int64")
-def is_int64(t):
- return t.id == lib.Type_INT64
-
-
-@doc(is_null, datatype="uint8")
-def is_uint8(t):
- return t.id == lib.Type_UINT8
-
-
-@doc(is_null, datatype="uint16")
-def is_uint16(t):
- return t.id == lib.Type_UINT16
-
-
-@doc(is_null, datatype="uint32")
-def is_uint32(t):
- return t.id == lib.Type_UINT32
-
-
-@doc(is_null, datatype="uint64")
-def is_uint64(t):
- return t.id == lib.Type_UINT64
-
-
-@doc(is_null, datatype="floating point numeric")
-def is_floating(t):
- return t.id in _FLOATING_TYPES
-
-
-@doc(is_null, datatype="float16 (half-precision)")
-def is_float16(t):
- return t.id == lib.Type_HALF_FLOAT
-
-
-@doc(is_null, datatype="float32 (single precision)")
-def is_float32(t):
- return t.id == lib.Type_FLOAT
-
-
-@doc(is_null, datatype="float64 (double precision)")
-def is_float64(t):
- return t.id == lib.Type_DOUBLE
-
-
-@doc(is_null, datatype="list")
-def is_list(t):
- return t.id == lib.Type_LIST
-
-
-@doc(is_null, datatype="large list")
-def is_large_list(t):
- return t.id == lib.Type_LARGE_LIST
-
-
-@doc(is_null, datatype="fixed size list")
-def is_fixed_size_list(t):
- return t.id == lib.Type_FIXED_SIZE_LIST
-
-
-@doc(is_null, datatype="list view")
-def is_list_view(t):
- return t.id == lib.Type_LIST_VIEW
-
-
-@doc(is_null, datatype="large list view")
-def is_large_list_view(t):
- return t.id == lib.Type_LARGE_LIST_VIEW
-
-
-@doc(is_null, datatype="struct")
-def is_struct(t):
- return t.id == lib.Type_STRUCT
-
-
-@doc(is_null, datatype="union")
-def is_union(t):
- return t.id in _UNION_TYPES
-
-
-@doc(is_null, datatype="nested type")
-def is_nested(t):
- return t.id in _NESTED_TYPES
-
-
-@doc(is_null, datatype="run-end encoded")
-def is_run_end_encoded(t):
- return t.id == lib.Type_RUN_END_ENCODED
-
-
-@doc(is_null, datatype="date, time, timestamp or duration")
-def is_temporal(t):
- return t.id in _TEMPORAL_TYPES
-
-
-@doc(is_null, datatype="timestamp")
-def is_timestamp(t):
- return t.id == lib.Type_TIMESTAMP
-
-
-@doc(is_null, datatype="duration")
-def is_duration(t):
- return t.id == lib.Type_DURATION
-
-
-@doc(is_null, datatype="time")
-def is_time(t):
- return t.id in _TIME_TYPES
-
-
-@doc(is_null, datatype="time32")
-def is_time32(t):
- return t.id == lib.Type_TIME32
-
-
-@doc(is_null, datatype="time64")
-def is_time64(t):
- return t.id == lib.Type_TIME64
-
-
-@doc(is_null, datatype="variable-length binary")
-def is_binary(t):
- return t.id == lib.Type_BINARY
-
-
-@doc(is_null, datatype="large variable-length binary")
-def is_large_binary(t):
- return t.id == lib.Type_LARGE_BINARY
-
-
-@doc(method="is_string")
-def is_unicode(t):
- """
- Alias for {method}.
-
- Parameters
- ----------
- t : DataType
- """
- return is_string(t)
-
-
-@doc(is_null, datatype="string (utf8 unicode)")
-def is_string(t):
- return t.id == lib.Type_STRING
-
-
-@doc(is_unicode, method="is_large_string")
-def is_large_unicode(t):
- return is_large_string(t)
-
-
-@doc(is_null, datatype="large string (utf8 unicode)")
-def is_large_string(t):
- return t.id == lib.Type_LARGE_STRING
-
-
-@doc(is_null, datatype="fixed size binary")
-def is_fixed_size_binary(t):
- return t.id == lib.Type_FIXED_SIZE_BINARY
-
-
-@doc(is_null, datatype="variable-length binary view")
-def is_binary_view(t):
- return t.id == lib.Type_BINARY_VIEW
-
-
-@doc(is_null, datatype="variable-length string (utf-8) view")
-def is_string_view(t):
- return t.id == lib.Type_STRING_VIEW
-
-
-@doc(is_null, datatype="date")
-def is_date(t):
- return t.id in _DATE_TYPES
-
-
-@doc(is_null, datatype="date32 (days)")
-def is_date32(t):
- return t.id == lib.Type_DATE32
-
-
-@doc(is_null, datatype="date64 (milliseconds)")
-def is_date64(t):
- return t.id == lib.Type_DATE64
-
-
-@doc(is_null, datatype="map")
-def is_map(t):
- return t.id == lib.Type_MAP
-
-
-@doc(is_null, datatype="decimal")
-def is_decimal(t):
- return t.id in _DECIMAL_TYPES
-
-
-@doc(is_null, datatype="decimal128")
-def is_decimal128(t):
- return t.id == lib.Type_DECIMAL128
-
-
-@doc(is_null, datatype="decimal256")
-def is_decimal256(t):
- return t.id == lib.Type_DECIMAL256
-
-
-@doc(is_null, datatype="dictionary-encoded")
-def is_dictionary(t):
- return t.id == lib.Type_DICTIONARY
-
-
-@doc(is_null, datatype="interval")
-def is_interval(t):
- return t.id == lib.Type_INTERVAL_MONTH_DAY_NANO
-
-
-@doc(is_null, datatype="primitive type")
-def is_primitive(t):
- return lib._is_primitive(t.id)
+ is_float_value,
+ ensure_type,
Review Comment:
Despite not beginning with a underscore, this is not a public function, so we should not export it.
##########
python/pyarrow/types.pxi:
##########
@@ -5401,6 +5428,1069 @@ def is_float_value(object obj):
return IsPyFloat(obj)
+def _is_integer(data_type):
+ """
+ This function checks whether the `data_type` is an integer type, which
+ includes signed and unsigned integers of various bit widths (8, 16, 32, 64 bits).
Review Comment:
Same for other functions below.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1591277023
##########
python/pyarrow/includes/libarrow.pxd:
##########
@@ -3026,3 +3023,34 @@ cdef extern from "arrow/python/udf.h" namespace "arrow::py" nogil:
cdef extern from "arrow/compute/cast.h" namespace "arrow::compute":
CResult[CDatum] Cast(const CDatum& value, const CCastOptions& options)
+
+cdef extern from "arrow/type_traits.h" namespace "arrow":
+ c_bool c_is_integer "is_integer"(Type type_id)
Review Comment:
Looks great to me!
The failures do not seem connected, not sure there are open issues for them though. Will look into it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2063751556
@pitrou @AlenkaF
Can you help me complete this PR?
- Must-be-solved [part](https://github.com/apache/arrow/pull/40761#discussion_r1562439775)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2104849866
@pitrou Hello. I think the changes match what we wanted. Could you review them when you have time? Thank you.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1545002423
##########
python/pyarrow/types.py:
##########
@@ -64,17 +82,17 @@ def is_boolean(t):
@doc(is_null, datatype="any integer")
def is_integer(t):
- return t.id in _INTEGER_TYPES
+ return is_integer_type(t)
Review Comment:
hello. I would appreciate it if you could review it when you have time. thank you! cc @pitrou
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2117355569
Aha... I see that maintaining both C++ and Python code identically may complicate maintenance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1537408964
##########
python/pyarrow/type_traits.pxi:
##########
@@ -0,0 +1,394 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from pyarrow.includes.libarrow cimport (is_integer,
+ is_signed_integer,
+ is_unsigned_integer,
+ is_floating,
+ is_numeric,
+ is_decimal,
+ is_run_end_type,
+ is_primitive,
+ is_base_binary_like,
+ is_binary_like,
+ is_large_binary_like,
+ is_binary,
+ is_string,
+ is_temporal,
+ is_time,
+ is_date,
+ is_interval,
+ is_dictionary,
+ is_fixed_size_binary,
+ is_fixed_width,
+ is_var_length_list,
+ is_list,
+ is_list_like,
+ is_var_length_list_like,
+ is_list_view,
+ is_nested,
+ is_union,
+ bit_width,
+ offset_bit_width)
+
+
+def is_integer_type(data_type):
+ """
+ Check if the data type is an integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_integer(data_type.id)
+
+
+def is_signed_integer_type(data_type):
+ """
+ Check if the data type is a signed integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_signed_integer(data_type.id)
+
+
+def is_unsigned_integer_type(data_type):
+ """
+ Check if the data type is an unsigned integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_unsigned_integer(data_type.id)
+
+
+def is_floating_type(data_type):
+ """
+ Check if the data type is a floating type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_floating(data_type.id)
+
+
+def is_numeric_type(data_type):
+ """
+ Check if the data type is a numeric type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_numeric(data_type.id)
+
+
+def is_decimal_type(data_type):
+ """
+ Check if the data type is a decimal type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_decimal(data_type.id)
+
+
+def is_run_end_type_py(data_type):
+ """
+ Check if the data type is a run end type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_run_end_type(data_type.id)
+
+
+def is_primitive_type(data_type):
+ """
+ Check if the data type is a primitive type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_primitive(data_type.id)
+
+
+def is_base_binary_like_type(data_type):
+ """
+ Check if the data type is a base_binary_like type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_base_binary_like(data_type.id)
+
+
+def is_binary_like_type(data_type):
+ """
+ Check if the data type is a _binary_like type.
Review Comment:
In other words, please use your own judgement when writing docstrings. Don't just write them mechanically.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] WIP: GH-40282: Use C++ type traits [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2016444753
:warning: GitHub issue #40282 **has been automatically assigned in GitHub** to PR creator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1542343616
##########
python/pyarrow/types.py:
##########
@@ -64,17 +82,17 @@ def is_boolean(t):
@doc(is_null, datatype="any integer")
def is_integer(t):
- return t.id in _INTEGER_TYPES
+ return is_integer_type(t)
Review Comment:
I wrote the wrapper for the C++ function to use the `is_integer` function, thinking someone might use it while working with pyarrow for compatibility. Should we not consider this aspect?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1549833432
##########
python/pyarrow/type_traits.pxi:
##########
Review Comment:
I changed the code as you said. Please check when you have time! Thank you always.
Also, for your information, it seems that one CI failure is related to the part you are currently checking.
- https://github.com/apache/arrow/issues/40974
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1548985506
##########
python/pyarrow/type_traits.pxi:
##########
Review Comment:
I think having a separate file for type traits is a good idea. But I would mimic what is already done for `is_primitive` which is the only function from `types.py` that is a C++ binding. Here is the code:
https://github.com/apache/arrow/blob/41a989c81616aea103e554521fa6d6209ffa248d/python/pyarrow/types.pxi#L145-L147
Using only `_` before the function name is clearer and the comment explaining it is simply a redirect is clear and good to have.
This would also resolve the [suggestion from Antoine](https://github.com/apache/arrow/pull/40761#discussion_r1537413290), I think.
##########
python/pyarrow/type_traits.pxi:
##########
@@ -0,0 +1,394 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from pyarrow.includes.libarrow cimport (is_integer,
+ is_signed_integer,
+ is_unsigned_integer,
+ is_floating,
+ is_numeric,
+ is_decimal,
+ is_run_end_type,
+ is_primitive,
+ is_base_binary_like,
+ is_binary_like,
+ is_large_binary_like,
+ is_binary,
+ is_string,
+ is_temporal,
+ is_time,
+ is_date,
+ is_interval,
+ is_dictionary,
+ is_fixed_size_binary,
+ is_fixed_width,
+ is_var_length_list,
+ is_list,
+ is_list_like,
+ is_var_length_list_like,
+ is_list_view,
+ is_nested,
+ is_union,
+ bit_width,
+ offset_bit_width)
+
+
+def is_integer_type(data_type):
+ """
+ Check if the data type is an integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_integer(data_type.id)
+
+
+def is_signed_integer_type(data_type):
+ """
+ Check if the data type is a signed integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_signed_integer(data_type.id)
+
+
+def is_unsigned_integer_type(data_type):
+ """
+ Check if the data type is an unsigned integer type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_unsigned_integer(data_type.id)
+
+
+def is_floating_type(data_type):
+ """
+ Check if the data type is a floating type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_floating(data_type.id)
+
+
+def is_numeric_type(data_type):
+ """
+ Check if the data type is a numeric type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_numeric(data_type.id)
+
+
+def is_decimal_type(data_type):
+ """
+ Check if the data type is a decimal type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_decimal(data_type.id)
+
+
+def is_run_end_type_py(data_type):
+ """
+ Check if the data type is a run end type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_run_end_type(data_type.id)
+
+
+def is_primitive_type(data_type):
+ """
+ Check if the data type is a primitive type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_primitive(data_type.id)
+
+
+def is_base_binary_like_type(data_type):
+ """
+ Check if the data type is a base_binary_like type.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+ """
+ return is_base_binary_like(data_type.id)
+
+
+def is_binary_like_type(data_type):
+ """
+ Check if the data type is a _binary_like type.
Review Comment:
It is looking much better, thanks! I think you could remove the first sentence, and maybe the last ("Useful for ..."). The middle portions of the docstrings are quite clear already.
##########
python/pyarrow/type_traits.pxi:
##########
@@ -0,0 +1,721 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from pyarrow.includes.libarrow cimport (is_integer,
+ is_signed_integer,
+ is_unsigned_integer,
+ is_floating,
+ is_numeric,
+ is_decimal,
+ is_run_end_type,
+ is_primitive,
+ is_base_binary_like,
+ is_binary_like,
+ is_large_binary_like,
+ is_binary,
+ is_string,
+ is_temporal,
+ is_time,
+ is_date,
+ is_interval,
+ is_dictionary,
+ is_fixed_size_binary,
+ is_fixed_width,
+ is_var_length_list,
+ is_list,
+ is_list_like,
+ is_var_length_list_like,
+ is_list_view,
+ is_nested,
+ is_union,
+ bit_width,
+ offset_bit_width)
+
+
+def is_integer_type(data_type):
+ """
+ Check if the data type is an integer type.
+
+ This function checks whether the `data_type` is an integer type, which
+ includes signed and unsigned integers of various bit widths (8, 16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is an integer type before performing
+ operations that are only valid for integers.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check against the set of supported integer types.
+
+ Returns
+ -------
+ bool
+ True if `data_type` is an integer type, False otherwise.
+ """
+ return is_integer(data_type.id)
+
+
+def is_signed_integer_type(data_type):
+ """
+ Check if the data type is a signed integer type.
+
+ This function checks whether the `data_type` is a signed integer type,
+ which includes signed integers of various bit widths (8, 16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is a signed integer type before
+ performing operations that are only valid for signed integers.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is a signed integer type, False otherwise.
+ """
+ return is_signed_integer(data_type.id)
+
+
+def is_unsigned_integer_type(data_type):
+ """
+ Check if the data type is an unsigned integer type.
+
+ This function checks whether the `data_type` is an unsigned integer type,
+ which includes unsigned integers of various bit widths (8, 16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is an unsigned integer type before
+ performing operations that are only valid for unsigned integers.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is an unsigned integer type, False otherwise.
+ """
+ return is_unsigned_integer(data_type.id)
+
+
+def is_floating_type(data_type):
+ """
+ Check if the data type is a floating type.
+
+ This function checks whether the `data_type` is a floating type, which includes
+ floating point numbers of various bit widths (16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is a floating type before performing
+ operations that are only valid for floating point numbers.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is a floating type, False otherwise.
+ """
+ return is_floating(data_type.id)
+
+
+def is_numeric_type(data_type):
+ """
+ Check if the data type is a numeric type.
+
+ This function checks whether the `data_type` is a numeric type, which includes
+ integers and floating point numbers with specific bit widths. Integer types
+ include signed and unsigned integers of various bit widths (8, 16, 32, 64 bits),
+ while floating point types include floating point numbers of various bit widths
+ (16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is a numeric type before performing
+ operations that are only valid for numeric types.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is a numeric type, False otherwise.
+ """
+ return is_numeric(data_type.id)
+
+
+def is_decimal_type(data_type):
+ """
+ Check if the data type is a decimal type.
+
+ This function checks whether the `data_type` is a decimal type, which includes
+ fixed-point decimal numbers with specific precision and scale.
+
+ Useful for ensuring that a given data type is a decimal type before performing
+ operations that are only valid for decimal numbers.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is a decimal type, False otherwise.
+ """
+ return is_decimal(data_type.id)
+
+
+def is_run_end_type_py(data_type):
+ """
+ Check if the data type is a run end type.
+
+ This function checks whether the `data_type` is a run end type, which includes
+ integers of various bit widths (16, 32, 64 bits).
+
+ Useful for ensuring that a given data type is a run end type before performing
+ operations that are only valid for run end types.
+
+ Parameters
+ ----------
+ data_type : DataType
+ The data type to check
+
+ Returns
+ -------
+ bool
+ True if `data_type` is a run end type, False otherwise.
+ """
+ return is_run_end_type(data_type.id)
+
+
+def is_primitive_type(data_type):
+ """
+ Check if the data type is a primitive type.
+
+ This function checks whether the `data_type` is a primitive type, which includes
+ integers, floating point numbers, dates (days since the UNIX epoch and milliseconds
+ since the UNIX epoch), times (seconds and milliseconds since midnight),
+ timestamp (milliseconds since the UNIX epoch), and duration (elapsed time in
+ seconds, milliseconds, microseconds, and nanoseconds), and intervals (months,
Review Comment:
```suggestion
timestamp (milliseconds since the UNIX epoch), duration (elapsed time in
seconds, milliseconds, microseconds, and nanoseconds) and intervals (months,
```
Booleana are also included here.
Also, I think it would be enough to only keep the content without the details in `(...)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1553345115
##########
python/pyarrow/type_traits.pxi:
##########
@@ -0,0 +1,585 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from pyarrow.includes.libarrow cimport (is_integer,
+ is_signed_integer,
+ is_unsigned_integer,
+ is_floating,
+ is_numeric,
+ is_decimal,
+ is_run_end_type,
+ is_primitive,
+ is_base_binary_like,
+ is_binary_like,
+ is_large_binary_like,
+ is_binary,
+ is_string,
+ is_temporal,
+ is_time,
+ is_date,
+ is_interval,
+ is_dictionary,
+ is_fixed_size_binary,
+ is_fixed_width,
+ is_var_length_list,
+ is_list,
+ is_list_like,
+ is_var_length_list_like,
+ is_list_view,
+ is_nested,
+ is_union,
+ bit_width,
+ offset_bit_width)
+
+# These functions are simply a redirect, the official APIs are in pyarrow.types.
Review Comment:
Thank you for review.
I migrated functions to `types.pxi` file and deleted `type_traits.pxi` file. Does what I've done fit your intentions?
Do you think docstring is also unnecessary? Actually I had no intention of adding a docstring. This was added because it was requested as CI was being performed.
Or are you still talking about why you do wrapping? This part replaces the content mentioned previously.
> I understand that pyarrow has a wide user base, and to avoid breaking compatibility, I've made sure that functions in the form of `is_${type}` can still operate as intended. (If I'm mistaken, please let me know.)
If I have misunderstood your intention, I would appreciate it if you could explain it in a little more detail. I actually lack a general understanding of the pyarrow code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1553576958
##########
python/pyarrow/types.py:
##########
@@ -59,92 +69,92 @@ def is_null(t):
@doc(is_null, datatype="boolean")
def is_boolean(t):
- return t.id == lib.Type_BOOL
+ return _is_primitive(t) and _bit_width(t) == 1
Review Comment:
No, it means you would define `is_boolean` directly in `types.pxi`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1553590571
##########
python/pyarrow/types.py:
##########
@@ -59,92 +69,92 @@ def is_null(t):
@doc(is_null, datatype="boolean")
def is_boolean(t):
- return t.id == lib.Type_BOOL
+ return _is_primitive(t) and _bit_width(t) == 1
Review Comment:
Okay... I will try that. Thank you for your response!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1537413290
##########
python/pyarrow/types.py:
##########
@@ -64,17 +82,17 @@ def is_boolean(t):
@doc(is_null, datatype="any integer")
def is_integer(t):
- return t.id in _INTEGER_TYPES
+ return is_integer_type(t)
Review Comment:
Hmm... why are we defining two sets of functions exactly? We should have either `is_integer` or `is_integer_type`, not both.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: Use C++ type traits [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2016498640
:warning: GitHub issue #40282 **has been automatically assigned in GitHub** to PR creator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1591793569
##########
python/pyarrow/includes/libarrow.pxd:
##########
@@ -3026,3 +3023,34 @@ cdef extern from "arrow/python/udf.h" namespace "arrow::py" nogil:
cdef extern from "arrow/compute/cast.h" namespace "arrow::compute":
CResult[CDatum] Cast(const CDatum& value, const CCastOptions& options)
+
+cdef extern from "arrow/type_traits.h" namespace "arrow":
+ c_bool c_is_integer "is_integer"(Type type_id)
Review Comment:
Opened https://github.com/apache/arrow/issues/41563 for the failing builds
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1545002540
##########
python/pyarrow/types.py:
##########
@@ -20,29 +20,47 @@
from pyarrow.lib import (is_boolean_value, # noqa
is_integer_value,
- is_float_value)
+ is_float_value,
+ is_integer_type,
+ is_signed_integer_type,
+ is_unsigned_integer_type,
+ is_floating_type,
+ is_numeric_type,
+ is_decimal_type,
+ is_run_end_type_py,
+ is_primitive_type,
+ is_base_binary_like_type,
+ is_binary_like_type,
+ is_large_binary_like_type,
+ is_binary_type,
+ is_string_type,
+ is_temporal_type,
+ is_time_type,
+ is_date_type,
+ is_interval_type,
+ is_dictionary_type,
+ is_fixed_size_binary_type,
+ is_fixed_width_type,
+ is_var_length_list_type,
+ is_list_type,
+ is_list_like_type,
+ is_var_length_list_like_type,
+ is_list_view_type,
+ is_nested_type,
+ is_union_type,
+ is_bit_width_type,
+ is_offset_bit_width_type)
import pyarrow.lib as lib
from pyarrow.util import doc
-_SIGNED_INTEGER_TYPES = {lib.Type_INT8, lib.Type_INT16, lib.Type_INT32,
- lib.Type_INT64}
-_UNSIGNED_INTEGER_TYPES = {lib.Type_UINT8, lib.Type_UINT16, lib.Type_UINT32,
- lib.Type_UINT64}
-_INTEGER_TYPES = _SIGNED_INTEGER_TYPES | _UNSIGNED_INTEGER_TYPES
-_FLOATING_TYPES = {lib.Type_HALF_FLOAT, lib.Type_FLOAT, lib.Type_DOUBLE}
-_DECIMAL_TYPES = {lib.Type_DECIMAL128, lib.Type_DECIMAL256}
_DATE_TYPES = {lib.Type_DATE32, lib.Type_DATE64}
_TIME_TYPES = {lib.Type_TIME32, lib.Type_TIME64}
_INTERVAL_TYPES = {lib.Type_INTERVAL_MONTH_DAY_NANO}
_TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
Review Comment:
hello. I would appreciate it if you could review it when you have time. thank you! cc @AlenkaF
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1591109342
##########
python/pyarrow/includes/libarrow.pxd:
##########
@@ -3026,3 +3023,34 @@ cdef extern from "arrow/python/udf.h" namespace "arrow::py" nogil:
cdef extern from "arrow/compute/cast.h" namespace "arrow::compute":
CResult[CDatum] Cast(const CDatum& value, const CCastOptions& options)
+
+cdef extern from "arrow/type_traits.h" namespace "arrow":
+ c_bool c_is_integer "is_integer"(Type type_id)
Review Comment:
@AlenkaF Thank you for your review and advice.
Inspired by your suggestions, I further explored the code and made some modifications.
Could this be what @pitrou intended?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on code in PR #40761:
URL: https://github.com/apache/arrow/pull/40761#discussion_r1562440409
##########
python/pyarrow/types.pxi:
##########
@@ -5401,6 +5428,1069 @@ def is_float_value(object obj):
return IsPyFloat(obj)
+def _is_integer(data_type):
+ """
+ This function checks whether the `data_type` is an integer type, which
+ includes signed and unsigned integers of various bit widths (8, 16, 32, 64 bits).
Review Comment:
I fixed it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2041032884
@pitrou Hello.
I've structured functions in `types.pxi` to enable type checking.
The `types.py` is used to import and expose functions from `types.pxi` for use with pyarrow.
- When a function with the same name already exists in `type_traits.h` (e.g., `is_intger`), I prefix it with `_` in `types.pxi`, but when importing, I remove the `_` using `as` (e.g., `_is_integer as is_integer`) to expose it (`_is_integer as is_integer`). For instance, it's exposed as `py.types.is_integer`.
- For functions that don't exist yet, I define them without the `_` prefix (e.g., `is_boolean`) and utilize functions within `type_traits.h` wherever possible to check types.
I think I've grasped the intention behind the code adjustments. I hope this is the right intention! Please review it again when you have time. Thank you always.
ps. Also, I attempted to omit `.types.` in calls, but encountered the following error related to compatibility with `pandas`, hence I maintained the use of `.types.` for invoking functions.
<details><summary>error message</summary>
```
================================================================================================================== FAILURES ==================================================================================================================
_______________________________________________________________________________________ test_extension_to_pandas_storage_type[registered_period_type2] _______________________________________________________________________________________
registered_period_type = (PeriodTypeWithToPandasDtype(DataType(int64)), <class 'pyarrow.lib.ExtensionArray'>)
@pytest.mark.pandas
def test_extension_to_pandas_storage_type(registered_period_type):
period_type, _ = registered_period_type
np_arr = np.array([1, 2, 3, 4], dtype='i8')
storage = pa.array([1, 2, 3, 4], pa.int64())
arr = pa.ExtensionArray.from_storage(period_type, storage)
if isinstance(period_type, PeriodTypeWithToPandasDtype):
pandas_dtype = period_type.to_pandas_dtype()
else:
pandas_dtype = np_arr.dtype
# Test arrays
> result = arr.to_pandas()
pyarrow/tests/test_extension_type.py:1490:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pyarrow/array.pxi:899: in pyarrow.lib._PandasConvertible.to_pandas
return self._to_pandas(options, categories=categories,
pyarrow/array.pxi:1544: in pyarrow.lib.Array._to_pandas
return _array_like_to_pandas(self, options, types_mapper=types_mapper)
pyarrow/array.pxi:1917: in pyarrow.lib._array_like_to_pandas
arr = dtype.__from_arrow__(obj)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/dtypes/dtypes.py:1146: in __from_arrow__
data, mask = pyarrow_array_to_numpy_and_mask(arr, dtype=np.dtype(np.int64))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = <pyarrow.lib.ExtensionArray object at 0x16e060460>
[
1,
2,
3,
4
], dtype = dtype('int64')
def pyarrow_array_to_numpy_and_mask(
arr, dtype: np.dtype
) -> tuple[np.ndarray, np.ndarray]:
"""
Convert a primitive pyarrow.Array to a numpy array and boolean mask based
on the buffers of the Array.
At the moment pyarrow.BooleanArray is not supported.
Parameters
----------
arr : pyarrow.Array
dtype : numpy.dtype
Returns
-------
(data, mask)
Tuple of two numpy arrays with the raw data (with specified dtype) and
a boolean mask (validity mask, so False means missing)
"""
dtype = np.dtype(dtype)
> if pyarrow.types.is_null(arr.type):
E AttributeError: module 'pyarrow.types' has no attribute 'is_null'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/arrow/_arrow_utils.py:45: AttributeError
_________________________________________________________________________________________ test_convert_categories_to_array_with_string_pyarrow_dtype _________________________________________________________________________________________
def test_convert_categories_to_array_with_string_pyarrow_dtype():
# gh-33727: categories should be converted to pa.Array
if Version(pd.__version__) < Version("1.3.0"):
pytest.skip("PyArrow backed string data type introduced in pandas 1.3.0")
> df = pd.DataFrame({"x": ["foo", "bar", "foo"]}, dtype="string[pyarrow]")
pyarrow/tests/test_pandas.py:4173:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/frame.py:767: in __init__
mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/internals/construction.py:503: in dict_to_mgr
return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/internals/construction.py:119: in arrays_to_mgr
arrays, refs = _homogenize(arrays, index, dtype)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/internals/construction.py:629: in _homogenize
val = sanitize_array(val, index, dtype=dtype, copy=False)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/construction.py:596: in sanitize_array
subarr = cls._from_sequence(data, dtype=dtype, copy=copy)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/string_arrow.py:199: in _from_sequence
return cls(pa.array(result, type=pa.string(), from_pandas=True))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <[TypeError("object of type 'NoneType' has no len()") raised in repr()] ArrowStringArray object at 0x17ef27880>, values = <pyarrow.lib.StringArray object at 0x17efb0fa0>
[
"foo",
"bar",
"foo"
]
def __init__(self, values) -> None:
_chk_pyarrow_available()
> if isinstance(values, (pa.Array, pa.ChunkedArray)) and pa.types.is_string(
values.type
):
E AttributeError: module 'pyarrow.types' has no attribute 'is_string'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/string_arrow.py:131: AttributeError
______________________________________________________________________________________________________ test_convert_to_extension_array _______________________________________________________________________________________________________
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x17fa37a90>
def test_convert_to_extension_array(monkeypatch):
# table converted from dataframe with extension types (so pandas_metadata
# has this information)
df = pd.DataFrame(
{'a': [1, 2, 3], 'b': pd.array([2, 3, 4], dtype='Int64'),
'c': [4, 5, 6]})
table = pa.table(df)
# Int64Dtype is recognized -> convert to extension block by default
# for a proper roundtrip
> result = table.to_pandas()
pyarrow/tests/test_pandas.py:4298:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pyarrow/array.pxi:899: in pyarrow.lib._PandasConvertible.to_pandas
return self._to_pandas(options, categories=categories,
pyarrow/table.pxi:4795: in pyarrow.lib.Table._to_pandas
df = table_to_dataframe(
pyarrow/pandas_compat.py:777: in table_to_dataframe
blocks = _table_to_blocks(options, table, categories, ext_columns_dtypes)
pyarrow/pandas_compat.py:1109: in _table_to_blocks
return [_reconstruct_block(item, columns, extension_columns)
pyarrow/pandas_compat.py:1109: in <listcomp>
return [_reconstruct_block(item, columns, extension_columns)
pyarrow/pandas_compat.py:737: in _reconstruct_block
pd_ext_arr = pandas_dtype.__from_arrow__(arr)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/numeric.py:100: in __from_arrow__
data, mask = pyarrow_array_to_numpy_and_mask(array, dtype=self.numpy_dtype)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = <pyarrow.lib.Int64Array object at 0x17fb04220>
[
2,
3,
4
], dtype = dtype('int64')
def pyarrow_array_to_numpy_and_mask(
arr, dtype: np.dtype
) -> tuple[np.ndarray, np.ndarray]:
"""
Convert a primitive pyarrow.Array to a numpy array and boolean mask based
on the buffers of the Array.
At the moment pyarrow.BooleanArray is not supported.
Parameters
----------
arr : pyarrow.Array
dtype : numpy.dtype
Returns
-------
(data, mask)
Tuple of two numpy arrays with the raw data (with specified dtype) and
a boolean mask (validity mask, so False means missing)
"""
dtype = np.dtype(dtype)
> if pyarrow.types.is_null(arr.type):
E AttributeError: module 'pyarrow.types' has no attribute 'is_null'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/arrow/_arrow_utils.py:45: AttributeError
______________________________________________________________________________________________ test_conversion_extensiontype_to_extensionarray _______________________________________________________________________________________________
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x17f95d3f0>
def test_conversion_extensiontype_to_extensionarray(monkeypatch):
# converting extension type to linked pandas ExtensionDtype/Array
storage = pa.array([1, 2, 3, 4], pa.int64())
arr = pa.ExtensionArray.from_storage(MyCustomIntegerType(), storage)
table = pa.table({'a': arr})
# extension type points to Int64Dtype, which knows how to create a
# pandas ExtensionArray
> result = arr.to_pandas()
pyarrow/tests/test_pandas.py:4344:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pyarrow/array.pxi:899: in pyarrow.lib._PandasConvertible.to_pandas
return self._to_pandas(options, categories=categories,
pyarrow/array.pxi:1544: in pyarrow.lib.Array._to_pandas
return _array_like_to_pandas(self, options, types_mapper=types_mapper)
pyarrow/array.pxi:1917: in pyarrow.lib._array_like_to_pandas
arr = dtype.__from_arrow__(obj)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = Int64Dtype(), array = <pyarrow.lib.ExtensionArray object at 0x17e88c160>
[
1,
2,
3,
4
]
def __from_arrow__(
self, array: pyarrow.Array | pyarrow.ChunkedArray
) -> BaseMaskedArray:
"""
Construct IntegerArray/FloatingArray from pyarrow Array/ChunkedArray.
"""
import pyarrow
from pandas.core.arrays.arrow._arrow_utils import (
pyarrow_array_to_numpy_and_mask,
)
array_class = self.construct_array_type()
pyarrow_type = pyarrow.from_numpy_dtype(self.type)
> if not array.type.equals(pyarrow_type) and not pyarrow.types.is_null(
array.type
):
E AttributeError: module 'pyarrow.types' has no attribute 'is_null'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/numeric.py:77: AttributeError
__________________________________________________________________________________________________ test_to_pandas_extension_dtypes_mapping ___________________________________________________________________________________________________
def test_to_pandas_extension_dtypes_mapping():
table = pa.table({'a': pa.array([1, 2, 3], pa.int64())})
# default use numpy dtype
result = table.to_pandas()
assert result['a'].dtype == np.dtype('int64')
# specify to override the default
> result = table.to_pandas(types_mapper={pa.int64(): pd.Int64Dtype()}.get)
pyarrow/tests/test_pandas.py:4380:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pyarrow/array.pxi:899: in pyarrow.lib._PandasConvertible.to_pandas
return self._to_pandas(options, categories=categories,
pyarrow/table.pxi:4795: in pyarrow.lib.Table._to_pandas
df = table_to_dataframe(
pyarrow/pandas_compat.py:777: in table_to_dataframe
blocks = _table_to_blocks(options, table, categories, ext_columns_dtypes)
pyarrow/pandas_compat.py:1109: in _table_to_blocks
return [_reconstruct_block(item, columns, extension_columns)
pyarrow/pandas_compat.py:1109: in <listcomp>
return [_reconstruct_block(item, columns, extension_columns)
pyarrow/pandas_compat.py:737: in _reconstruct_block
pd_ext_arr = pandas_dtype.__from_arrow__(arr)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/numeric.py:100: in __from_arrow__
data, mask = pyarrow_array_to_numpy_and_mask(array, dtype=self.numpy_dtype)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = <pyarrow.lib.Int64Array object at 0x17e88cee0>
[
1,
2,
3
], dtype = dtype('int64')
def pyarrow_array_to_numpy_and_mask(
arr, dtype: np.dtype
) -> tuple[np.ndarray, np.ndarray]:
"""
Convert a primitive pyarrow.Array to a numpy array and boolean mask based
on the buffers of the Array.
At the moment pyarrow.BooleanArray is not supported.
Parameters
----------
arr : pyarrow.Array
dtype : numpy.dtype
Returns
-------
(data, mask)
Tuple of two numpy arrays with the raw data (with specified dtype) and
a boolean mask (validity mask, so False means missing)
"""
dtype = np.dtype(dtype)
> if pyarrow.types.is_null(arr.type):
E AttributeError: module 'pyarrow.types' has no attribute 'is_null'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/arrow/_arrow_utils.py:45: AttributeError
____________________________________________________________________________________________________________ test_array_to_pandas ____________________________________________________________________________________________________________
def test_array_to_pandas():
if Version(pd.__version__) < Version("1.1"):
pytest.skip("ExtensionDtype to_pandas method missing")
for arr in [pd.period_range("2012-01-01", periods=3, freq="D").array,
pd.interval_range(1, 4).array]:
> result = pa.array(arr).to_pandas()
pyarrow/tests/test_pandas.py:4403:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pyarrow/array.pxi:899: in pyarrow.lib._PandasConvertible.to_pandas
return self._to_pandas(options, categories=categories,
pyarrow/array.pxi:1544: in pyarrow.lib.Array._to_pandas
return _array_like_to_pandas(self, options, types_mapper=types_mapper)
pyarrow/array.pxi:1917: in pyarrow.lib._array_like_to_pandas
arr = dtype.__from_arrow__(obj)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/dtypes/dtypes.py:1146: in __from_arrow__
data, mask = pyarrow_array_to_numpy_and_mask(arr, dtype=np.dtype(np.int64))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = <pyarrow.lib.ExtensionArray object at 0x17f993ca0>
[
15340,
15341,
15342
], dtype = dtype('int64')
def pyarrow_array_to_numpy_and_mask(
arr, dtype: np.dtype
) -> tuple[np.ndarray, np.ndarray]:
"""
Convert a primitive pyarrow.Array to a numpy array and boolean mask based
on the buffers of the Array.
At the moment pyarrow.BooleanArray is not supported.
Parameters
----------
arr : pyarrow.Array
dtype : numpy.dtype
Returns
-------
(data, mask)
Tuple of two numpy arrays with the raw data (with specified dtype) and
a boolean mask (validity mask, so False means missing)
"""
dtype = np.dtype(dtype)
> if pyarrow.types.is_null(arr.type):
E AttributeError: module 'pyarrow.types' has no attribute 'is_null'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/arrow/_arrow_utils.py:45: AttributeError
____________________________________________________________________________________________________ test_to_pandas_types_mapper_index[a] ____________________________________________________________________________________________________
index = 'a'
@pytest.mark.parametrize("index", ["a", ["a", "b"]])
def test_to_pandas_types_mapper_index(index):
if Version(pd.__version__) < Version("1.5.0"):
pytest.skip("ArrowDtype missing")
> df = pd.DataFrame(
{
"a": [1, 2],
"b": [3, 4],
"c": [5, 6],
},
dtype=pd.ArrowDtype(pa.int64()),
).set_index(index)
pyarrow/tests/test_pandas.py:4429:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/frame.py:693: in __init__
dtype = self._validate_dtype(dtype)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/generic.py:518: in _validate_dtype
if dtype.kind == "V":
properties.pyx:36: in pandas._libs.properties.CachedProperty.__get__
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = int64[pyarrow]
@cache_readonly
def kind(self) -> str:
> if pa.types.is_timestamp(self.pyarrow_dtype):
E AttributeError: module 'pyarrow.types' has no attribute 'is_timestamp'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/dtypes/dtypes.py:2205: AttributeError
_________________________________________________________________________________________________ test_to_pandas_types_mapper_index[index1] __________________________________________________________________________________________________
index = ['a', 'b']
@pytest.mark.parametrize("index", ["a", ["a", "b"]])
def test_to_pandas_types_mapper_index(index):
if Version(pd.__version__) < Version("1.5.0"):
pytest.skip("ArrowDtype missing")
> df = pd.DataFrame(
{
"a": [1, 2],
"b": [3, 4],
"c": [5, 6],
},
dtype=pd.ArrowDtype(pa.int64()),
).set_index(index)
pyarrow/tests/test_pandas.py:4429:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/frame.py:693: in __init__
dtype = self._validate_dtype(dtype)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/generic.py:518: in _validate_dtype
if dtype.kind == "V":
properties.pyx:36: in pandas._libs.properties.CachedProperty.__get__
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = int64[pyarrow]
@cache_readonly
def kind(self) -> str:
> if pa.types.is_timestamp(self.pyarrow_dtype):
E AttributeError: module 'pyarrow.types' has no attribute 'is_timestamp'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/dtypes/dtypes.py:2205: AttributeError
_____________________________________________________________________________________________________ test_array_to_pandas_types_mapper ______________________________________________________________________________________________________
def test_array_to_pandas_types_mapper():
# https://issues.apache.org/jira/browse/ARROW-9664
if Version(pd.__version__) < Version("1.2.0"):
pytest.skip("Float64Dtype extension dtype missing")
data = pa.array([1, 2, 3], pa.int64())
# Test with mapper function
types_mapper = {pa.int64(): pd.Int64Dtype()}.get
> result = data.to_pandas(types_mapper=types_mapper)
pyarrow/tests/test_pandas.py:4452:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pyarrow/array.pxi:899: in pyarrow.lib._PandasConvertible.to_pandas
return self._to_pandas(options, categories=categories,
pyarrow/array.pxi:1544: in pyarrow.lib.Array._to_pandas
return _array_like_to_pandas(self, options, types_mapper=types_mapper)
pyarrow/array.pxi:1917: in pyarrow.lib._array_like_to_pandas
arr = dtype.__from_arrow__(obj)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/numeric.py:100: in __from_arrow__
data, mask = pyarrow_array_to_numpy_and_mask(array, dtype=self.numpy_dtype)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = <pyarrow.lib.Int64Array object at 0x17f6f41c0>
[
1,
2,
3
], dtype = dtype('int64')
def pyarrow_array_to_numpy_and_mask(
arr, dtype: np.dtype
) -> tuple[np.ndarray, np.ndarray]:
"""
Convert a primitive pyarrow.Array to a numpy array and boolean mask based
on the buffers of the Array.
At the moment pyarrow.BooleanArray is not supported.
Parameters
----------
arr : pyarrow.Array
dtype : numpy.dtype
Returns
-------
(data, mask)
Tuple of two numpy arrays with the raw data (with specified dtype) and
a boolean mask (validity mask, so False means missing)
"""
dtype = np.dtype(dtype)
> if pyarrow.types.is_null(arr.type):
E AttributeError: module 'pyarrow.types' has no attribute 'is_null'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/arrow/_arrow_utils.py:45: AttributeError
_________________________________________________________________________________________________ test_chunked_array_to_pandas_types_mapper __________________________________________________________________________________________________
@pytest.mark.pandas
def test_chunked_array_to_pandas_types_mapper():
# https://issues.apache.org/jira/browse/ARROW-9664
if Version(pd.__version__) < Version("1.2.0"):
pytest.skip("Float64Dtype extension dtype missing")
data = pa.chunked_array([pa.array([1, 2, 3], pa.int64())])
assert isinstance(data, pa.ChunkedArray)
# Test with mapper function
types_mapper = {pa.int64(): pd.Int64Dtype()}.get
> result = data.to_pandas(types_mapper=types_mapper)
pyarrow/tests/test_pandas.py:4477:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pyarrow/array.pxi:899: in pyarrow.lib._PandasConvertible.to_pandas
return self._to_pandas(options, categories=categories,
pyarrow/table.pxi:475: in pyarrow.lib.ChunkedArray._to_pandas
return _array_like_to_pandas(self, options, types_mapper=types_mapper)
pyarrow/array.pxi:1917: in pyarrow.lib._array_like_to_pandas
arr = dtype.__from_arrow__(obj)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/numeric.py:100: in __from_arrow__
data, mask = pyarrow_array_to_numpy_and_mask(array, dtype=self.numpy_dtype)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = <pyarrow.lib.Int64Array object at 0x17f6f5fc0>
[
1,
2,
3
], dtype = dtype('int64')
def pyarrow_array_to_numpy_and_mask(
arr, dtype: np.dtype
) -> tuple[np.ndarray, np.ndarray]:
"""
Convert a primitive pyarrow.Array to a numpy array and boolean mask based
on the buffers of the Array.
At the moment pyarrow.BooleanArray is not supported.
Parameters
----------
arr : pyarrow.Array
dtype : numpy.dtype
Returns
-------
(data, mask)
Tuple of two numpy arrays with the raw data (with specified dtype) and
a boolean mask (validity mask, so False means missing)
"""
dtype = np.dtype(dtype)
> if pyarrow.types.is_null(arr.type):
E AttributeError: module 'pyarrow.types' has no attribute 'is_null'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/arrow/_arrow_utils.py:45: AttributeError
____________________________________________________________________________________________________________ test_table_join_asof ____________________________________________________________________________________________________________
@pytest.mark.dataset
def test_table_join_asof():
t1 = pa.Table.from_pydict({
"colA": [1, 1, 5, 6, 7],
"col2": ["a", "b", "a", "b", "f"]
})
t2 = pa.Table.from_pydict({
"colB": [2, 9, 15],
"col3": ["a", "b", "g"],
"colC": [1., 3., 5.]
})
r = t1.join_asof(
t2, on="colA", by="col2", tolerance=1,
right_on="colB", right_by="col3",
)
> assert r.combine_chunks() == pa.table({
"colA": [1, 1, 5, 6, 7],
"col2": ["a", "b", "a", "b", "f"],
"colC": [1., None, None, None, None],
})
E assert pyarrow.Table...ll,null,null]] == pyarrow.Table...ll,null,null]]
E Use -v to get more diff
pyarrow/tests/test_table.py:2892: AssertionError
_________________________________________________________________________________________________ test_categories_with_string_pyarrow_dtype __________________________________________________________________________________________________
tempdir = PosixPath('/private/var/folders/cp/mk09m76d0ws97l5r7k7vdjh40000gn/T/pytest-of-lama/pytest-123/test_categories_with_string_py0')
@pytest.mark.pandas
def test_categories_with_string_pyarrow_dtype(tempdir):
# gh-33727: writing to parquet should not fail
if Version(pd.__version__) < Version("1.3.0"):
pytest.skip("PyArrow backed string data type introduced in pandas 1.3.0")
> df1 = pd.DataFrame({"x": ["foo", "bar", "foo"]}, dtype="string[pyarrow]")
pyarrow/tests/parquet/test_pandas.py:504:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/frame.py:767: in __init__
mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/internals/construction.py:503: in dict_to_mgr
return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/internals/construction.py:119: in arrays_to_mgr
arrays, refs = _homogenize(arrays, index, dtype)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/internals/construction.py:629: in _homogenize
val = sanitize_array(val, index, dtype=dtype, copy=False)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/construction.py:596: in sanitize_array
subarr = cls._from_sequence(data, dtype=dtype, copy=copy)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/string_arrow.py:199: in _from_sequence
return cls(pa.array(result, type=pa.string(), from_pandas=True))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <[TypeError("object of type 'NoneType' has no len()") raised in repr()] ArrowStringArray object at 0x304d98580>, values = <pyarrow.lib.StringArray object at 0x304d92980>
[
"foo",
"bar",
"foo"
]
def __init__(self, values) -> None:
_chk_pyarrow_available()
> if isinstance(values, (pa.Array, pa.ChunkedArray)) and pa.types.is_string(
values.type
):
E AttributeError: module 'pyarrow.types' has no attribute 'is_string'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/string_arrow.py:131: AttributeError
___________________________________________________________________________________________ test_write_to_dataset_pandas_preserve_extensiondtypes ____________________________________________________________________________________________
tempdir = PosixPath('/private/var/folders/cp/mk09m76d0ws97l5r7k7vdjh40000gn/T/pytest-of-lama/pytest-123/test_write_to_dataset_pandas_p0')
@pytest.mark.pandas
def test_write_to_dataset_pandas_preserve_extensiondtypes(tempdir):
df = pd.DataFrame({'part': 'a', "col": [1, 2, 3]})
df['col'] = df['col'].astype("Int64")
table = pa.table(df)
pq.write_to_dataset(
table, str(tempdir / "case1"), partition_cols=['part'],
)
> result = pq.read_table(str(tempdir / "case1")).to_pandas()
pyarrow/tests/parquet/test_pandas.py:531:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pyarrow/array.pxi:899: in pyarrow.lib._PandasConvertible.to_pandas
return self._to_pandas(options, categories=categories,
pyarrow/table.pxi:4795: in pyarrow.lib.Table._to_pandas
df = table_to_dataframe(
pyarrow/pandas_compat.py:777: in table_to_dataframe
blocks = _table_to_blocks(options, table, categories, ext_columns_dtypes)
pyarrow/pandas_compat.py:1109: in _table_to_blocks
return [_reconstruct_block(item, columns, extension_columns)
pyarrow/pandas_compat.py:1109: in <listcomp>
return [_reconstruct_block(item, columns, extension_columns)
pyarrow/pandas_compat.py:737: in _reconstruct_block
pd_ext_arr = pandas_dtype.__from_arrow__(arr)
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/numeric.py:100: in __from_arrow__
data, mask = pyarrow_array_to_numpy_and_mask(array, dtype=self.numpy_dtype)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
arr = <pyarrow.lib.Int64Array object at 0x3058fa4a0>
[
1,
2,
3
], dtype = dtype('int64')
def pyarrow_array_to_numpy_and_mask(
arr, dtype: np.dtype
) -> tuple[np.ndarray, np.ndarray]:
"""
Convert a primitive pyarrow.Array to a numpy array and boolean mask based
on the buffers of the Array.
At the moment pyarrow.BooleanArray is not supported.
Parameters
----------
arr : pyarrow.Array
dtype : numpy.dtype
Returns
-------
(data, mask)
Tuple of two numpy arrays with the raw data (with specified dtype) and
a boolean mask (validity mask, so False means missing)
"""
dtype = np.dtype(dtype)
> if pyarrow.types.is_null(arr.type):
E AttributeError: module 'pyarrow.types' has no attribute 'is_null'
../../../anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/arrays/arrow/_arrow_utils.py:45: AttributeError
============================================================================================================== warnings summary ==============================================================================================================
pyarrow/tests/test_pandas.py::TestConvertMetadata::test_empty_list_metadata
pyarrow/tests/test_pandas.py::TestConvertListTypes::test_empty_list_roundtrip
/Users/lama/anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/dtypes/missing.py:576: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
return lib.array_equivalent_object(left, right)
pyarrow/tests/test_pandas.py: 4 warnings
pyarrow/tests/parquet/test_data_types.py: 4 warnings
pyarrow/tests/parquet/test_pandas.py: 2 warnings
pyarrow/tests/parquet/test_parquet_file.py: 6 warnings
/Users/lama/anaconda3/envs/pyarrow-dev-310/lib/python3.10/site-packages/pandas/core/dtypes/missing.py:577: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if not lib.array_equivalent_object(left[~mask], right[~mask]):
pyarrow/tests/test_pandas.py::TestConvertListTypes::test_list_view_to_pandas_with_null_values[ListViewArray]
pyarrow/tests/test_pandas.py::TestConvertListTypes::test_list_view_to_pandas_with_null_values[LargeListViewArray]
/Users/lama/workspace/arrow-new/python/pyarrow/tests/test_pandas.py:2576: FutureWarning: Mismatched null-like values nan and None found. In a future version, pandas equality-testing functions (e.g. assert_frame_equal) will consider these not-matching and raise.
tm.assert_series_equal(actual, expected)
pyarrow/tests/test_pandas.py::TestConvertListTypes::test_list_view_to_pandas_multiple_chunks[ListViewArray]
pyarrow/tests/test_pandas.py::TestConvertListTypes::test_list_view_to_pandas_multiple_chunks[LargeListViewArray]
/Users/lama/workspace/arrow-new/python/pyarrow/tests/test_pandas.py:2598: FutureWarning: Mismatched null-like values nan and None found. In a future version, pandas equality-testing functions (e.g. assert_frame_equal) will consider these not-matching and raise.
tm.assert_series_equal(actual, expected)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================================================== short test summary info ===========================================================================================================
FAILED pyarrow/tests/test_extension_type.py::test_extension_to_pandas_storage_type[registered_period_type2] - AttributeError: module 'pyarrow.types' has no attribute 'is_null'
FAILED pyarrow/tests/test_pandas.py::test_convert_categories_to_array_with_string_pyarrow_dtype - AttributeError: module 'pyarrow.types' has no attribute 'is_string'
FAILED pyarrow/tests/test_pandas.py::test_convert_to_extension_array - AttributeError: module 'pyarrow.types' has no attribute 'is_null'
FAILED pyarrow/tests/test_pandas.py::test_conversion_extensiontype_to_extensionarray - AttributeError: module 'pyarrow.types' has no attribute 'is_null'
FAILED pyarrow/tests/test_pandas.py::test_to_pandas_extension_dtypes_mapping - AttributeError: module 'pyarrow.types' has no attribute 'is_null'
FAILED pyarrow/tests/test_pandas.py::test_array_to_pandas - AttributeError: module 'pyarrow.types' has no attribute 'is_null'
FAILED pyarrow/tests/test_pandas.py::test_to_pandas_types_mapper_index[a] - AttributeError: module 'pyarrow.types' has no attribute 'is_timestamp'
FAILED pyarrow/tests/test_pandas.py::test_to_pandas_types_mapper_index[index1] - AttributeError: module 'pyarrow.types' has no attribute 'is_timestamp'
FAILED pyarrow/tests/test_pandas.py::test_array_to_pandas_types_mapper - AttributeError: module 'pyarrow.types' has no attribute 'is_null'
FAILED pyarrow/tests/test_pandas.py::test_chunked_array_to_pandas_types_mapper - AttributeError: module 'pyarrow.types' has no attribute 'is_null'
FAILED pyarrow/tests/test_table.py::test_table_join_asof - assert pyarrow.Table...ll,null,null]] == pyarrow.Table...ll,null,null]]
FAILED pyarrow/tests/parquet/test_pandas.py::test_categories_with_string_pyarrow_dtype - AttributeError: module 'pyarrow.types' has no attribute 'is_string'
FAILED pyarrow/tests/parquet/test_pandas.py::test_write_to_dataset_pandas_preserve_extensiondtypes - AttributeError: module 'pyarrow.types' has no attribute 'is_null'
======================================================================== 13 failed, 7116 passed, 515 skipped, 15 xfailed, 1 xpassed, 22 warnings in 106.98s (0:01:46) ========================================================================
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40282: [Python] Use C++ type traits [arrow]
Posted by "llama90 (via GitHub)" <gi...@apache.org>.
llama90 commented on PR #40761:
URL: https://github.com/apache/arrow/pull/40761#issuecomment-2115139836
From your description and the mention by @pitrou, I understood the following:
> There is an is_nested function in C++, perhaps we can use it instead of relying on hand-maintained constants on the Python side? Same for some of the other predicates actually (I see that _INTERVAL_TYPES is only holding a single kind of interval?)
- For the `_${TYPE}_TYPES`, only replace with C++ validation functions where possible.
From a straightforward view, the cases that can be replaced with C++ functions are as follows:
- ✅ `_SIGNED_INTEGER_TYPES` = `constexpr bool is_signed_integer(Type::type type_id)`
- ✅ `_UNSIGNED_INTEGER_TYPES` = `constexpr bool is_unsigned_integer(Type::type type_id)`
- ✅ `_INTEGER_TYPES` = `constexpr bool is_integer(Type::type type_id)`
- ✅ `_FLOATING_TYPES` = `constexpr bool is_floating(Type::type type_id)`
- ✅ `_DECIMAL_TYPES` = `constexpr bool is_decimal(Type::type type_id)`
- ✅ `_DATE_TYPES` = `constexpr bool is_date(Type::type type_id)`
- ✅ `_TIME_TYPES` = `constexpr bool is_time(Type::type type_id)`
- `_INTERVAL_TYPES`
- `_TEMPORAL_TYPES`
- ✅ `_UNION_TYPES` = `constexpr bool is_union(Type::type type_id)`
- `_NESTED_TYPES`
In this case, do you intend to only replace the functions marked with ✅? Or are you considering modifying the C++ functions to align with the Python implementation as well?
- For `is_interval`, the C++ code also checks for `INTERVAL_MONTHS` and `INTERVAL_DAY_TIME`.
- For `is_temporal`, the C++ code does not check for `DURATION`.
- For `is_nested`, the C++ code also checks for `RUN_END_ENCODED`.
<details><summary>is_interval, is_temporal, and is_nested</summary>
```cpp
/// \brief Check for an interval type
///
/// \param[in] type_id the type-id to check
/// \return whether type-id is an interval type one
constexpr bool is_interval(Type::type type_id) {
switch (type_id) {
case Type::INTERVAL_MONTHS:
case Type::INTERVAL_DAY_TIME:
case Type::INTERVAL_MONTH_DAY_NANO:
return true;
default:
break;
}
return false;
}
/// \brief Check for a temporal type
///
/// \param[in] type_id the type-id to check
/// \return whether type-id is a temporal type one
constexpr bool is_temporal(Type::type type_id) {
switch (type_id) {
case Type::DATE32:
case Type::DATE64:
case Type::TIME32:
case Type::TIME64:
case Type::TIMESTAMP:
return true;
default:
break;
}
return false;
}
/// \brief Check for a nested type
///
/// \param[in] type_id the type-id to check
/// \return whether type-id is a nested type one
constexpr bool is_nested(Type::type type_id) {
switch (type_id) {
case Type::LIST:
case Type::LARGE_LIST:
case Type::LIST_VIEW:
case Type::LARGE_LIST_VIEW:
case Type::FIXED_SIZE_LIST:
case Type::MAP:
case Type::STRUCT:
case Type::SPARSE_UNION:
case Type::DENSE_UNION:
case Type::RUN_END_ENCODED:
return true;
default:
break;
}
return false;
}
```
</details>
Moreover, while it is certainly easier to simply apply what you have mentioned, from a long-term perspective, exporting C++ functions to replace equivalent Python code raises questions about the rationale for maintaining them separately. I would like to seek further opinions on this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org