nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: bids-standard/pybids
Pull request #449 (2019-05-24 02:19:51)

ENH: Add BIDSFile.__fspath__ to work with pathlib
This allows us to use `Path(layout.get(...)[0])`, or to pass `BIDSFile`s to functions that expect path-likes, such as `os.stat` in 3.6+, or `pandas.read_csv`.

Nothing revolutionary, but somewhat convenient when you forget that `get()` returns `BIDSFile`s.

effigies: I guess it only works in 3.6+. Worth adding to give a hand to 3.6+ apps?

Patch:
diff --git a/bids/layout/models.py b/bids/layout/models.py
index 41f49596..c0ac8b1b 100644
--- a/bids/layout/models.py
+++ b/bids/layout/models.py
@@ -152,6 +152,9 @@ class BIDSFile(Base):
     def __repr__(self):
         return "<{} filename='{}'>".format(self.__class__.__name__, self.path)
 
+    def __fspath__(self):
+        return self.path
+
     @reconstructor
     def _init_on_load(self):
         self._data = None


Test patch:
diff --git a/bids/layout/tests/test_models.py b/bids/layout/tests/test_models.py
index b9075f5e..c06928c6 100644
--- a/bids/layout/tests/test_models.py
+++ b/bids/layout/tests/test_models.py
@@ -1,7 +1,9 @@
+import sys
 import os
 import pytest
 import bids
 import copy
+from pathlib import Path
 
 from sqlalchemy import create_engine
 from sqlalchemy.orm import sessionmaker
@@ -219,3 +221,11 @@ def test_bidsfile_get_entities(layout_synthetic):
     md2 = bf.get_entities(metadata=None)
     assert md == md2
     assert set(md.keys()) == md_ents | file_ents
+
+
+@pytest.mark.xfail(sys.version_info < (3, 6), reason="os.PathLike introduced in Python 3.6")
+def test_bidsfile_fspath(sample_bidsfile):
+    bf = sample_bidsfile
+    bf_path = Path(bf)
+    assert bf_path == Path(bf.path)
+    assert bf_path.read_text() == '###'
Repository: bids-standard/pybids
Pull request #458 (2019-07-09 21:16:58)

FIX: Restore <entity>=None query returning files lacking the entity
Starting with a test showing that we don't have it.

@tyarkoni Is this easy? I haven't dug into SQLAlchemy in a long time.


Patch:
diff --git a/bids/layout/layout.py b/bids/layout/layout.py
index c4b20c17..a2c8b748 100644
--- a/bids/layout/layout.py
+++ b/bids/layout/layout.py
@@ -780,22 +780,30 @@ class BIDSLayout(object):
             query = query.join(BIDSFile.tags)
             regex = kwargs.get('regex_search', False)
             for name, val in filters.items():
+                if isinstance(val, (list, tuple)) and len(val) == 1:
+                    val = val[0]
+
+                if val is None:
+                    drop = query.filter(
+                        BIDSFile.tags.any(entity_name=name))
+                    query = query.except_(drop)
+                    continue
+
                 if regex:
                     if isinstance(val, (list, tuple)):
                         val_clause = sa.or_(*[Tag._value.op('REGEXP')(str(v))
                                               for v in val])
                     else:
                         val_clause = Tag._value.op('REGEXP')(val)
-                    subq = sa.and_(Tag.entity_name == name, val_clause)
-                    query = query.filter(BIDSFile.tags.any(subq))
                 else:
                     if isinstance(val, (list, tuple)):
-                        subq = sa.and_(Tag.entity_name == name,
-                                       Tag._value.in_(val))
-                        query = query.filter(BIDSFile.tags.any(subq))
+                        val_clause = Tag._value.in_(val)
                     else:
-                        query = query.filter(
-                            BIDSFile.tags.any(entity_name=name, _value=val))
+                        val_clause = Tag._value == val
+
+                subq = sa.and_(Tag.entity_name == name, val_clause)
+                query = query.filter(BIDSFile.tags.any(subq))
+
         return query
 
     def get_collections(self, level, types=None, variables=None, merge=False,


Test patch:
diff --git a/bids/layout/tests/test_layout.py b/bids/layout/tests/test_layout.py
index 1b80c0f3..2a6acc66 100644
--- a/bids/layout/tests/test_layout.py
+++ b/bids/layout/tests/test_layout.py
@@ -222,6 +222,17 @@ def test_get_return_type_dir(layout_7t_trt, layout_7t_trt_relpath):
     assert target == res2
 
 
+def test_get_val_none(layout_7t_trt):
+    t1w_files = layout_7t_trt.get(subject='01', ses='1', suffix='T1w')
+    assert len(t1w_files) == 1
+    assert 'acq' not in t1w_files[0].path
+    t1w_files = layout_7t_trt.get(subject='01', ses='1', suffix='T1w', acquisition=None)
+    assert len(t1w_files) == 1
+    t1w_files = layout_7t_trt.get(subject='01', ses='1', suffix='T1w', acquisition=[None])
+    assert len(t1w_files) == 1
+    bold_files = layout_7t_trt.get(subject='01', ses='1', suffix='bold', acquisition=None)
+    assert len(bold_files) == 0
+
 
 def test_get_return_sorted(layout_7t_trt):
     bids_files = layout_7t_trt.get(target='subject')
Repository: bids-standard/pybids
Pull request #508 (2019-09-26 18:42:44)

ENH: Raise ValueError if BIDSLayout.build_path fails to match any pattern
This will fail on the next line anyways if built is None, but at least this is more descriptive


Patch:
diff --git a/bids/layout/layout.py b/bids/layout/layout.py
index d274f2f6..dd7e00aa 100644
--- a/bids/layout/layout.py
+++ b/bids/layout/layout.py
@@ -1203,6 +1203,8 @@ class BIDSLayout(object):
                     seen_configs.add(c)
 
         built = build_path(source, path_patterns, strict)
+        if built is None:
+            raise ValueError("Unable to construct build path with source {}".format(source))
         to_check = os.path.join(os.path.sep, built)
 
         if not validate or BIDSValidator().is_bids(to_check):


Test patch:
diff --git a/bids/layout/tests/test_path_building.py b/bids/layout/tests/test_path_building.py
index e498f60e..8457c95b 100644
--- a/bids/layout/tests/test_path_building.py
+++ b/bids/layout/tests/test_path_building.py
@@ -25,3 +25,9 @@ def test_invalid_file_construction(layout):
     
     target = "sub-01/func/sub-01_task-resting-state_run-1_bold.nii.gz"
     assert layout.build_path(ents, validate=False) == target
+
+
+def test_failed_file_construction(layout):
+    ents = dict(subject='01', fakekey='foobar')
+    with pytest.raises(ValueError):
+        layout.build_path(ents)
Repository: bids-standard/pybids
Pull request #623 (2020-05-30 04:10:20)

Add explicit warning message when users pass in filters as a dictionary keyword
Closes: #622 

Helps direct users to not pass in `filters` as a dictionary directly, but should have them do:

`layout.get(**filters)`

vs

`layout.get(filters=filters)`, which results in returning the entire bids root.


Patch:
diff --git a/bids/layout/layout.py b/bids/layout/layout.py
index f0ef306c..38482400 100644
--- a/bids/layout/layout.py
+++ b/bids/layout/layout.py
@@ -937,6 +937,13 @@ class BIDSLayout(object):
 
         entities = self.get_entities()
 
+        # error check on users accidentally passing in filters
+        if isinstance(filters.get('filters'), dict):
+            raise RuntimeError('You passed in filters as a dictionary named '
+                               'filters; please pass the keys in as named '
+                               'keywords to the `get()` call. For example: '
+                               '`layout.get(**filters)`.')
+
         # Strip leading periods if extensions were passed
         if 'extension' in filters:
             exts = listify(filters['extension'])


Test patch:
diff --git a/bids/layout/tests/test_layout.py b/bids/layout/tests/test_layout.py
index e2a39375..fc2090e3 100644
--- a/bids/layout/tests/test_layout.py
+++ b/bids/layout/tests/test_layout.py
@@ -688,6 +688,12 @@ def test_get_with_invalid_filters(layout_ds005):
     allow_res = l.get(subject='12', amazing=True, invalid_filters='allow')
     assert allow_res == []
 
+    # assert warning when filters are passed in
+    filters = {'subject': '1'}
+    with pytest.raises(RuntimeError, match='You passed in filters as a dictionary'):
+        l.get(filters=filters)
+    # Correct call:
+    l.get(**filters)
 
 
 def test_load_layout(layout_synthetic_nodb, db_dir):
Repository: bids-standard/pybids
Pull request #809 (2022-01-25 18:23:42)

ENH: Add new `Query` for optional entities
Mimics `Query.ANY` but allows matching when entity is not present altogether.
See https://github.com/bids-standard/pybids/issues/808


Patch:
diff --git a/bids/layout/layout.py b/bids/layout/layout.py
index 1088cf2d..d710ccf5 100644
--- a/bids/layout/layout.py
+++ b/bids/layout/layout.py
@@ -753,6 +753,8 @@ class BIDSLayout(object):
                 if val is None or val == Query.NONE:
                     join_method = query.outerjoin
                     val_clause = tag_alias._value.is_(None)
+                elif val == Query.OPTIONAL:
+                    continue
                 elif val == Query.ANY:
                     val_clause = tag_alias._value.isnot(None)
                 elif regex:
@@ -1315,4 +1317,5 @@ class BIDSLayout(object):
 class Query(enum.Enum):
     """Enums for use with BIDSLayout.get()."""
     NONE = 1 # Entity must not be present
-    ANY = 2  # Entity must be defined, but with an arbitrary value
+    REQUIRED = ANY = 2  # Entity must be defined, but with an arbitrary value
+    OPTIONAL = 3  # Entity may or may not be defined


Test patch:
diff --git a/bids/layout/tests/test_layout.py b/bids/layout/tests/test_layout.py
index be4ee4ec..88f49650 100644
--- a/bids/layout/tests/test_layout.py
+++ b/bids/layout/tests/test_layout.py
@@ -321,6 +321,23 @@ def test_get_val_enum_any(layout_7t_trt):
     assert len(bold_files) == 2
 
 
+def test_get_val_enum_any_optional(layout_7t_trt, layout_ds005):
+    # layout with sessions
+    query = {
+        "subject": "01",
+        "run": 1,
+        "suffix": "bold",
+    }
+    bold_files = layout_7t_trt.get(session=Query.OPTIONAL, **query)
+    assert len(bold_files) == 3
+
+    # layout without sessions
+    bold_files = layout_ds005.get(session=Query.REQUIRED, **query)
+    assert not bold_files
+    bold_files = layout_ds005.get(session=Query.OPTIONAL, **query)
+    assert len(bold_files) == 1
+
+
 def test_get_return_sorted(layout_7t_trt):
     bids_files = layout_7t_trt.get(target='subject')
     paths = [r.path for r in bids_files]
Repository: slawlor/ractor
Pull request #298 (2024-12-06 13:12:59)

fix: get supervisor method typo
There is an additional i in the get supervisor method which is not an issue but it's not correct.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/slawlor/ractor/pull/298?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 82.40%. Comparing base [(`ceef493`)](https://app.codecov.io/gh/slawlor/ractor/commit/ceef4931af6d5007fe375efeceec258992b18ebb?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor) to head [(`1c94dca`)](https://app.codecov.io/gh/slawlor/ractor/commit/1c94dcac99b98fc3917aeaae1b41d7e67bf7ede7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #298   +/-   ##
=======================================
  Coverage   82.40%   82.40%           
=======================================
  Files          60       60           
  Lines       10914    10914           
=======================================
  Hits         8994     8994           
  Misses       1920     1920           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/slawlor/ractor/pull/298?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Sean+Lawlor).


Patch:
diff --git a/ractor/src/actor/actor_cell.rs b/ractor/src/actor/actor_cell.rs
index b823d41..2106978 100644
--- a/ractor/src/actor/actor_cell.rs
+++ b/ractor/src/actor/actor_cell.rs
@@ -545,7 +545,7 @@ impl ActorCell {
     ///
     /// Returns [None] if this actor has no supervisor at the given instance or
     /// [Some(ActorCell)] supervisor if one is configured.
-    pub fn try_get_superivisor(&self) -> Option<ActorCell> {
+    pub fn try_get_supervisor(&self) -> Option<ActorCell> {
         self.inner.tree.try_get_supervisor()
     }
 


Test patch:
diff --git a/ractor/src/actor/tests/supervisor.rs b/ractor/src/actor/tests/supervisor.rs
index ed073ee..ff5f45f 100644
--- a/ractor/src/actor/tests/supervisor.rs
+++ b/ractor/src/actor/tests/supervisor.rs
@@ -97,7 +97,7 @@ async fn test_supervision_panic_in_post_startup() {
         .await
         .expect("Child panicked on startup");
 
-    let maybe_sup = child_ref.try_get_superivisor();
+    let maybe_sup = child_ref.try_get_supervisor();
     assert!(maybe_sup.is_some());
     assert_eq!(maybe_sup.map(|a| a.get_id()), Some(supervisor_ref.get_id()));