Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
df521f3
change is_nested() to use C++ type traits
llama90 Mar 23, 2024
1daac63
apply lint
llama90 Mar 23, 2024
5c67223
update to maintain compatibility
llama90 Mar 23, 2024
0f60359
update type_traits to expose all type check functions provided
llama90 Mar 23, 2024
818a7ab
update to code readability
llama90 Mar 23, 2024
085f67c
update docstring
llama90 Mar 24, 2024
edc1f9b
apply lint
llama90 Mar 24, 2024
38750b7
delete not used types
llama90 Mar 24, 2024
cbaada0
update by self-review
llama90 Mar 24, 2024
4d18b7e
enhance docstring to help users understand how to use the function
llama90 Mar 28, 2024
3d38c7e
update is_integer to check bit width
llama90 Mar 28, 2024
837e153
fix return type for bit_width and offset_bit_width
llama90 Mar 28, 2024
b1d9b10
update to support the logic usign the provided functions
llama90 Mar 28, 2024
8810b4b
update docstring removing 'Check if~' and 'Useful for'
llama90 Apr 3, 2024
cec4b11
update docstring removing (...)
llama90 Apr 3, 2024
e9a4954
update function to start with _ prefix
llama90 Apr 3, 2024
974df0c
Update python/pyarrow/type_traits.pxi
llama90 Apr 4, 2024
30adfec
apply lint
llama90 Apr 4, 2024
8f08f46
delete type_traits.pxi
llama90 Apr 5, 2024
153de4b
migrate functions to types.pxi and expose through types.py
llama90 Apr 6, 2024
cbd5c2e
apply lint
llama90 Apr 6, 2024
06f1f1e
update by self-review
llama90 Apr 6, 2024
ed78341
add docstring to avoid below error
llama90 Apr 6, 2024
c583351
update test_types to avoid pa.types.
llama90 Apr 11, 2024
ac1d5f9
unexport ensure_type function
llama90 Apr 11, 2024
4ba8af0
update docstring
llama90 Apr 11, 2024
9b2e795
update extern statements
llama90 May 6, 2024
3bbc1e2
fix code for test_numpy_array_protocol
llama90 May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ cdef class Array(_PandasConvertible):
return np.array(values, dtype=dtype, copy=False)

values = self.to_numpy(zero_copy_only=False)
if copy is True and is_numeric(self.type.id) and self.null_count == 0:
if copy is True and is_numeric(self.type) and self.null_count == 0:
# to_numpy did not yet make a copy (is_numeric = integer/floats, no decimal)
return np.array(values, dtype=dtype, copy=True)

Expand Down
2 changes: 1 addition & 1 deletion python/pyarrow/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def cast(arr, target_type=None, safe=None, options=None, memory_pool=None):
" or pass a value for 'options'")

if options is None:
target_type = pa.types.lib.ensure_type(target_type)
target_type = pa.lib.ensure_type(target_type)
if safe is False:
options = CastOptions.unsafe(target_type)
else:
Expand Down
34 changes: 31 additions & 3 deletions python/pyarrow/includes/libarrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
CDataTypeLayout layout()
c_string ToString()

c_bool is_primitive(Type type)
c_bool is_numeric(Type type)

cdef cppclass CArrayData" arrow::ArrayData":
shared_ptr[CDataType] type
int64_t length
Expand Down Expand Up @@ -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)
Comment thread
AlenkaF marked this conversation as resolved.
Outdated
c_bool c_is_signed_integer "is_signed_integer"(Type type_id)
c_bool c_is_unsigned_integer "is_unsigned_integer"(Type type_id)
c_bool c_is_floating "is_floating"(Type type_id)
c_bool c_is_numeric "is_numeric"(Type type_id)
c_bool c_is_decimal "is_decimal"(Type type_id)
c_bool c_is_run_end "is_run_end_type"(Type type_id)
c_bool c_is_primitive "is_primitive"(Type type_id)
c_bool c_is_base_binary_like "is_base_binary_like"(Type type_id)
c_bool c_is_binary_like "is_binary_like"(Type type_id)
c_bool c_is_large_binary_like "is_large_binary_like"(Type type_id)
c_bool c_is_binary "is_binary"(Type type_id)
c_bool c_is_string "is_string"(Type type_id)
c_bool c_is_temporal "is_temporal"(Type type_id)
c_bool c_is_time "is_time"(Type type_id)
c_bool c_is_date "is_date"(Type type_id)
c_bool c_is_interval "is_interval"(Type type_id)
c_bool c_is_dictionary "is_dictionary"(Type type_id)
c_bool c_is_fixed_size_binary "is_fixed_size_binary"(Type type_id)
c_bool c_is_fixed_width "is_fixed_width"(Type type_id)
c_bool c_is_var_length_list "is_var_length_list"(Type type_id)
c_bool c_is_list "is_list"(Type type_id)
c_bool c_is_list_like "is_list_like"(Type type_id)
c_bool c_is_var_length_list_like "is_var_length_list_like"(Type type_id)
c_bool c_is_list_view "is_list_view"(Type type_id)
c_bool c_is_nested "is_nested"(Type type_id)
c_bool c_is_union "is_union"(Type type_id)
int c_bit_width "bit_width"(Type type_id)
int c_offset_bit_width "offset_bit_width"(Type type_id)
26 changes: 13 additions & 13 deletions python/pyarrow/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

import numpy as np
import pyarrow as pa
import pyarrow.types as types
import pyarrow.tests.strategies as past
from pyarrow import types


def get_many_types():
Expand Down Expand Up @@ -1260,24 +1260,24 @@ def test_field_modified_copies():


def test_is_integer_value():
assert pa.types.is_integer_value(1)
assert pa.types.is_integer_value(np.int64(1))
assert not pa.types.is_integer_value('1')
assert types.is_integer_value(1)
assert types.is_integer_value(np.int64(1))
assert not types.is_integer_value('1')


def test_is_float_value():
assert not pa.types.is_float_value(1)
assert pa.types.is_float_value(1.)
assert pa.types.is_float_value(np.float64(1))
assert not pa.types.is_float_value('1.0')
assert not types.is_float_value(1)
assert types.is_float_value(1.)
assert types.is_float_value(np.float64(1))
assert not types.is_float_value('1.0')


def test_is_boolean_value():
assert not pa.types.is_boolean_value(1)
assert pa.types.is_boolean_value(True)
assert pa.types.is_boolean_value(False)
assert pa.types.is_boolean_value(np.bool_(True))
assert pa.types.is_boolean_value(np.bool_(False))
assert not types.is_boolean_value(1)
assert types.is_boolean_value(True)
assert types.is_boolean_value(False)
assert types.is_boolean_value(np.bool_(True))
assert types.is_boolean_value(np.bool_(False))


@h.settings(suppress_health_check=(h.HealthCheck.too_slow,))
Expand Down
Loading