MCPcopy Create free account
hub / github.com/dask/dask / register_pyarrow

Function register_pyarrow

dask/tokenize.py:390–434  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

388
389@normalize_token.register_lazy("pyarrow")
390def register_pyarrow():
391 import pyarrow as pa
392
393 @normalize_token.register(pa.DataType)
394 def normalize_datatype(dt):
395 return pickle.dumps(dt, protocol=4)
396
397 @normalize_token.register(pa.Table)
398 def normalize_table(dt):
399 return (
400 "pa.Table",
401 normalize_token(dt.schema),
402 normalize_token(dt.columns),
403 )
404
405 @normalize_token.register(pa.ChunkedArray)
406 def normalize_chunked_array(arr):
407 return (
408 "pa.ChunkedArray",
409 normalize_token(arr.type),
410 normalize_token(arr.chunks),
411 )
412
413 @normalize_token.register(pa.Array)
414 def normalize_array(arr):
415 buffers = arr.buffers()
416 # pyarrow does something clever when (de)serializing an array that has
417 # an empty validity map: The buffers for the deserialized array will
418 # have `None` instead of the empty validity map.
419 #
420 # We'll replicate that behavior here to ensure we get consistent
421 # tokenization.
422 buffers = arr.buffers()
423 if len(buffers) and buffers[0] is not None and arr.null_count == 0:
424 buffers[0] = None
425
426 return (
427 "pa.Array",
428 normalize_token(arr.type),
429 normalize_token(buffers),
430 )
431
432 @normalize_token.register(pa.Buffer)
433 def normalize_buffer(buf):
434 return ("pa.Buffer", hash_buffer_hex(buf))
435
436
437@normalize_token.register_lazy("numpy")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected