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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
