Skip to content

ARROW-2451: [Python] Handle non-object arrays more efficiently in custom serializer.#1887

Closed
robertnishihara wants to merge 1 commit intoapache:masterfrom
robertnishihara:pyarrowbools
Closed

ARROW-2451: [Python] Handle non-object arrays more efficiently in custom serializer.#1887
robertnishihara wants to merge 1 commit intoapache:masterfrom
robertnishihara:pyarrowbools

Conversation

@robertnishihara
Copy link
Copy Markdown
Contributor

Before this PR

import numpy as np
import pyarrow as pa

x = np.array(10 ** 8 * [True, False])
%time serialized_obj = pa.serialize(x).to_buffer()  # 10.4s
%time new_x = pa.deserialize(serialized_obj)  # 8.94s

x = np.array([str(i) for i in range(10 ** 7)])
%time serialized_obj = pa.serialize(x).to_buffer()  # 2.24s
%time new_x = pa.deserialize(serialized_obj)  # 2.03s

After this PR

import numpy as np
import pyarrow as pa

x = np.array(10 ** 8 * [True, False])
%time serialized_obj = pa.serialize(x).to_buffer()  # 117ms
%time new_x = pa.deserialize(serialized_obj)  # 265us

x = np.array([str(i) for i in range(10 ** 7)])
%time serialized_obj = pa.serialize(x).to_buffer()  # 174ms
%time new_x = pa.deserialize(serialized_obj)  # 13.2ms

cc @devin-petersohn @mitar @pcmoritz


def _serialize_numpy_array_list(obj):
return obj.tolist(), obj.dtype.str
if obj.dtype.str != '|O':
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sufficiently familiar with numpy dtypes to know if this |O is the only relevant special case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could check here for obj.dtype.hasobject: https://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.hasobject.html

for t in ["bool", "int8", "uint8", "int16", "uint16", "int32",
"uint32", "float16", "float32", "float64"]:
"uint32", "float16", "float32", "float64", "<U1", "<U2", "<U3",
"<U4", "|S1", "|S2", "|S3", "|S4", "|O"]:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

@pcmoritz pcmoritz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great solution, feel free to merge!

@robertnishihara
Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants