This is an automated email from the ASF dual-hosted git repository.

alenka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new a7f81404c6 GH-39579: [Python] fix raising ValueError on 
_ensure_partitioning (#39593)
a7f81404c6 is described below

commit a7f81404c656707e3f7f2dc2cc8b36b0dec2dadf
Author: 0x0000ffff <[email protected]>
AuthorDate: Mon Jan 22 22:27:05 2024 +0800

    GH-39579: [Python] fix raising ValueError on _ensure_partitioning (#39593)
    
    
    
    ### 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]>
---
 python/pyarrow/dataset.py            |  4 ++--
 python/pyarrow/tests/test_dataset.py | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/python/pyarrow/dataset.py b/python/pyarrow/dataset.py
index 9301a5fee5..f83753ac57 100644
--- a/python/pyarrow/dataset.py
+++ b/python/pyarrow/dataset.py
@@ -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
 
 
diff --git a/python/pyarrow/tests/test_dataset.py 
b/python/pyarrow/tests/test_dataset.py
index d473299f20..a4838d63a6 100644
--- a/python/pyarrow/tests/test_dataset.py
+++ b/python/pyarrow/tests/test_dataset.py
@@ -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([

Reply via email to