MCPcopy
hub / github.com/ray-project/ray / to_batch_format

Method to_batch_format

python/ray/data/block.py:493–518  ·  view source on GitHub ↗

Convert this block into the provided batch format. Args: batch_format: The batch format to convert this block to. Returns: This block formatted as the provided batch format.

(self, batch_format: Optional[str])

Source from the content-addressed store, hash-verified

491 return self.to_block()
492
493 def to_batch_format(self, batch_format: Optional[str]) -> DataBatch:
494 """Convert this block into the provided batch format.
495
496 Args:
497 batch_format: The batch format to convert this block to.
498
499 Returns:
500 This block formatted as the provided batch format.
501 """
502 if batch_format is None:
503 return self.to_block()
504 elif batch_format == "default" or batch_format == "native":
505 return self.to_default()
506 elif batch_format == "pandas":
507 return self.to_pandas()
508 elif batch_format == "pyarrow":
509 return self.to_arrow()
510 elif batch_format == "numpy":
511 return self.to_numpy()
512 elif batch_format == "cudf":
513 return self.to_cudf()
514 else:
515 raise ValueError(
516 f"The batch format must be one of {VALID_BATCH_FORMATS}, got: "
517 f"{batch_format}"
518 )
519
520 def size_bytes(self) -> int:
521 """Return the approximate size in bytes of this block."""

Callers 3

_apply_udf_to_groupsFunction · 0.80
_format_batchFunction · 0.80
arrow_batch_to_tensorsFunction · 0.80

Calls 6

to_blockMethod · 0.95
to_defaultMethod · 0.95
to_pandasMethod · 0.95
to_arrowMethod · 0.95
to_numpyMethod · 0.95
to_cudfMethod · 0.80

Tested by

no test coverage detected