nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: bids-standard/pybids
Pull request #307 (2018-11-28 13:10:18)

Support pathlib.Path and other Str-castable types
Pathlib is great, and works out of the box in pybids on python 3.4+. I only had to tweak the argument validation slightly.


Patch:
diff --git a/.travis.yml b/.travis.yml
index 21ba4cd0..41ff3afb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -57,6 +57,7 @@ before_install:
     - python --version # just to check
     - travis_retry pip install -U pip wheel  # needed at one point
     - travis_retry pip install pytest pytest-xdist pytest-cov codecov
+    - travis_retry pip install pathlib
 
 install:
 - pip install $EXTRA_PIP_FLAGS ".[analysis]"
diff --git a/bids/layout/layout.py b/bids/layout/layout.py
index 8c61d51c..e4d42d91 100644
--- a/bids/layout/layout.py
+++ b/bids/layout/layout.py
@@ -134,8 +134,14 @@ class BIDSLayout(Layout):
 
         # Validate arguments
         if not isinstance(root, six.string_types):
-            raise ValueError("root argument must be a string specifying the"
-                             " directory containing the BIDS dataset.")
+            # attempt to handle pathlib paths (or other types that can be cast as str)
+            # before giving up
+            try:
+                root = str(root)
+            except:
+                raise TypeError("root argument must be a string (or a type that "
+                        "supports casting to string, such as pathlib.Path)"
+                        " specifying the directory containing the BIDS dataset.")
         if not os.path.exists(root):
             raise ValueError("BIDS root does not exist: %s" % root)
 
diff --git a/bids/version.py b/bids/version.py
index ced943ea..e676a383 100644
--- a/bids/version.py
+++ b/bids/version.py
@@ -52,7 +52,7 @@ EXTRAS_REQUIRE = {
    # now deprecated installation schemes
    'analysis': []
 }
-TESTS_REQUIRE = ["pytest>=3.3.0"]
+TESTS_REQUIRE = ["pytest>=3.3.0", 'pathlib; python_version < "3.4"']
 
 
 def package_files(directory):


Test patch:
diff --git a/bids/layout/tests/test_rootpath.py b/bids/layout/tests/test_rootpath.py
new file mode 100644
index 00000000..d88ceba1
--- /dev/null
+++ b/bids/layout/tests/test_rootpath.py
@@ -0,0 +1,28 @@
+import sys
+import pytest
+from pathlib import Path
+from bids.layout import BIDSLayout
+from bids.tests import get_test_data_path
+"""
+test handling of pathlib Path file paths in place of old-style string type
+"""
+
+TESTPATH = Path(get_test_data_path()).joinpath("ds005")
+TESTSTR = str(TESTPATH)
+FALSEPATH = TESTPATH.joinpath("junk")
+FALSESTR = str(FALSEPATH)
+assert not FALSEPATH.exists()
+
+def test_strroot_pos():
+    layout = BIDSLayout(TESTSTR)
+
+def test_strroot_neg():
+    with pytest.raises(ValueError):
+        layout = BIDSLayout(FALSESTR)
+
+def test_pathroot_pos():
+    layout = BIDSLayout(TESTPATH)
+
+def test_pathroot_neg():
+    with pytest.raises(ValueError):
+        layout = BIDSLayout(FALSEPATH)
Repository: bids-standard/pybids
Pull request #396 (2019-02-26 17:41:37)

ENH: .get() - natural_sort BIDSFile entries as well for consistency
- also made the test on "dirs" return type verify that return value is sorted

will be useful as preventative measure for demos/tutorials to not change their output randomly


Patch:
diff --git a/bids/layout/layout.py b/bids/layout/layout.py
index 0f5ee694..2f92515a 100644
--- a/bids/layout/layout.py
+++ b/bids/layout/layout.py
@@ -559,6 +559,8 @@ class BIDSLayout(object):
             else:
                 raise ValueError("Invalid return_type specified (must be one "
                                  "of 'tuple', 'file', 'id', or 'dir'.")
+        else:
+            results = natural_sort(results, 'path')
 
         return results
 


Test patch:
diff --git a/bids/layout/tests/test_layout.py b/bids/layout/tests/test_layout.py
index 48288ca8..b02e191a 100644
--- a/bids/layout/tests/test_layout.py
+++ b/bids/layout/tests/test_layout.py
@@ -8,6 +8,7 @@ from bids.layout import BIDSLayout, parse_file_entities, add_config_paths
 from bids.layout.core import BIDSFile, Entity, Config
 from os.path import join, abspath, basename, dirname
 from bids.tests import get_test_data_path
+from bids.utils import natural_sort
 
 
 # Fixture uses in the rest of the tests
@@ -232,10 +233,21 @@ def test_bids_json(layout_7t_trt):
 def test_get_return_type_dir(layout_7t_trt):
     l = layout_7t_trt
     res = l.get(target='subject', return_type='dir')
-    for i in range(1, 11):
-        sub_dir = "sub-{:02d}".format(i)
-        assert os.path.join(get_test_data_path(), '7t_trt', sub_dir) in res
-    assert len(res) == 10
+    # returned directories should be in sorted order so we can match exactly
+    target = [
+        os.path.join(get_test_data_path(), '7t_trt', "sub-{:02d}".format(i))
+        for i in range(1, 11)
+    ]
+    assert target == res
+
+
+def test_get_return_sorted(layout_7t_trt):
+    bids_files = layout_7t_trt.get(target='subject')
+    paths = [r.path for r in bids_files]
+    assert natural_sort(paths) == paths
+
+    files = layout_7t_trt.get(target='subject', return_type='file')
+    assert files == paths
 
 
 def test_force_index(layout_ds005, layout_ds005_models):