Skip to content

Commit

Permalink
GH-39579: [Python] fix raising ValueError on _ensure_partitioning (#3…
Browse files Browse the repository at this point in the history
…9593)

### Rationale for this change
The `_ensure_partitioning` method in dataset.py is missing a "raise" which currently ignores bad scheme silently.

### What changes are included in this PR?

Fixed the typo.

### Are these changes tested?
Tried with new code that the exception is properly raised.

### Are there any user-facing changes?
No.

* Closes: #39579

Lead-authored-by: idailylife <[email protected]>
Co-authored-by: 0x0000ffff <[email protected]>
Co-authored-by: Alenka Frim <[email protected]>
Signed-off-by: AlenkaF <[email protected]>
  • Loading branch information
idailylife and AlenkaF authored Jan 22, 2024
1 parent c33ffb0 commit a7f8140
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/pyarrow/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ def _ensure_partitioning(scheme):
elif isinstance(scheme, (Partitioning, PartitioningFactory)):
pass
else:
ValueError("Expected Partitioning or PartitioningFactory, got {}"
.format(type(scheme)))
raise ValueError("Expected Partitioning or PartitioningFactory, got {}"
.format(type(scheme)))
return scheme


Expand Down
11 changes: 11 additions & 0 deletions python/pyarrow/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,17 @@ def test_partitioning():
load_back_table = load_back.to_table()
assert load_back_table.equals(table)

# test invalid partitioning input
with tempfile.TemporaryDirectory() as tempdir:
partitioning = ds.DirectoryPartitioning(partitioning_schema)
ds.write_dataset(table, tempdir,
format='ipc', partitioning=partitioning)
load_back = None
with pytest.raises(ValueError,
match="Expected Partitioning or PartitioningFactory"):
load_back = ds.dataset(tempdir, format='ipc', partitioning=int(0))
assert load_back is None


def test_partitioning_pickling(pickle_module):
schema = pa.schema([
Expand Down

0 comments on commit a7f8140

Please sign in to comment.