mirror of
https://github.com/vale981/ray
synced 2025-03-06 02:21:39 -05:00
[data] More informative exceptions in block impl (#24665)
This commit is contained in:
parent
93d61b6d48
commit
47edb497c5
3 changed files with 16 additions and 4 deletions
|
@ -36,7 +36,13 @@ class SimpleBlockBuilder(BlockBuilder[T]):
|
|||
self._size_estimator.add(item)
|
||||
|
||||
def add_block(self, block: List[T]) -> None:
|
||||
assert isinstance(block, list), block
|
||||
if not isinstance(block, list):
|
||||
raise TypeError(
|
||||
f"Got a block of type {type(block)}, expected list. "
|
||||
"If you are mapping a function, ensure it returns an "
|
||||
"object with the expected type. Block:\n"
|
||||
f"{block}"
|
||||
)
|
||||
self._items.extend(block)
|
||||
for item in block:
|
||||
self._size_estimator.add(item)
|
||||
|
|
|
@ -45,7 +45,13 @@ class TableBlockBuilder(BlockBuilder[T]):
|
|||
self._uncompacted_size.add(item)
|
||||
|
||||
def add_block(self, block: Any) -> None:
|
||||
assert isinstance(block, self._block_type), block
|
||||
if not isinstance(block, self._block_type):
|
||||
raise TypeError(
|
||||
f"Got a block of type {type(block)}, expected {self._block_type}."
|
||||
"If you are mapping a function, ensure it returns an "
|
||||
"object with the expected type. Block:\n"
|
||||
f"{block}"
|
||||
)
|
||||
accessor = BlockAccessor.for_block(block)
|
||||
self._tables.append(block)
|
||||
self._tables_size_bytes += accessor.size_bytes()
|
||||
|
|
|
@ -2960,11 +2960,11 @@ def test_groupby_map_groups_merging_invalid_result(ray_start_regular_shared):
|
|||
grouped = ds.groupby(lambda x: x)
|
||||
|
||||
# The UDF returns None, which is invalid.
|
||||
with pytest.raises(AssertionError):
|
||||
with pytest.raises(TypeError):
|
||||
grouped.map_groups(lambda x: None if x == [1] else x)
|
||||
|
||||
# The UDF returns a type that's different than the input type, which is invalid.
|
||||
with pytest.raises(AssertionError):
|
||||
with pytest.raises(TypeError):
|
||||
grouped.map_groups(lambda x: pd.DataFrame([1]) if x == [1] else x)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue