Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion of numpy boolean array to pyarrow boolean array isn't zero-copy #118

Open
sjperkins opened this issue Sep 6, 2024 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@sjperkins
Copy link
Member

sjperkins commented Sep 6, 2024

In both NumPy and CASA, booleans are represented by a byte (8-bits). However, Arrow represents booleans with a single bit.

This means that, in the case of np.bool_, this conversion is not a zero-copy:

# Convert to pyarrow array
pa_array = pa.array(np_array)

This means that it's not possible pass NumPy bool arrays as getcol result arguments, or as putcol data arguments.

It's easy enough to work around this by passing data.astype(np.uint8) in these instances, as arcae represents CASA booleans as arrow:uint8()

template <>
struct CasaDataTypeTraits<casacore::DataType::TpBool> {
using ArrowType = arrow::UInt8Type;
using CasaType = casacore::Bool;
static std::shared_ptr<arrow::DataType> ArrowDataType() { return arrow::uint8(); }
static constexpr bool is_complex = false;
};

but it'd probably be convenient for the user to do this within arcae itself, during the numpy <--> arrow conversion process.

@sjperkins sjperkins added enhancement New feature or request bug Something isn't working labels Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant