PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: dr-leo/pandaSDMX (python)

Issue:
Prune empty StructureMessage collections in to_pandas()
As raised by @dr-leo via e-mail:

> flows = ecb.dataflow()
>
> When I do 'to_pandas(flows)', the resulting DictLike has all the empty resources from the StructureMessage. I buy your Argument that at IM Level all supported resource types should be represented by an Attribute. However, I see no merit in representing absent resources by a key and empty dict.

Related to #79.

Pull request:
Skip empty StructureMessage attributes in write_structuremessage
Closes #90.

Patch:
diff --git a/pandasdmx/writer.py b/pandasdmx/writer.py
index 024ee8a..b596505 100644
--- a/pandasdmx/writer.py
+++ b/pandasdmx/writer.py
@@ -158,8 +158,12 @@ def write_structuremessage(obj, include=None, **kwargs):
         attrs &= all_contents
     attrs = sorted(attrs)
 
-    result = DictLike((a, write(getattr(obj, a), **kwargs))
-                      for a in attrs)
+    result = DictLike()
+    for a in attrs:
+        dl = write(getattr(obj, a), **kwargs)
+        if len(dl):
+            # Only add non-empty elements
+            result[a] = dl
 
     return result
 


Test patch:
diff --git a/tests/test_writer.py b/tests/test_writer.py
index 5c3280c..2aa61d0 100644
--- a/tests/test_writer.py
+++ b/tests/test_writer.py
@@ -1,6 +1,5 @@
 """Tests for pandasdmx/writer.py."""
 # TODO test all possible values of Writer.write() arguments
-# - asframe
 # - attribute
 # - fromfreq
 # - parsetime
@@ -102,6 +101,20 @@ def test_write_agencyscheme():
 
     assert data['organisation_scheme']['AGENCIES']['ESTAT'] == 'Eurostat'
 
+    # to_pandas only returns keys for non-empty attributes of StructureMessage
+    # https://github.com/dr-leo/pandaSDMX/issues/90
+    assert set(data.keys()) == {'organisation_scheme'}
+
+    # Attribute access works
+    assert data.organisation_scheme.AGENCIES.ESTAT == 'Eurostat'
+
+    with pytest.raises(AttributeError):
+        data.codelist
+    with pytest.raises(AttributeError):
+        data.dataflow
+    with pytest.raises(AttributeError):
+        data.structure
+
 
 def test_write_categoryscheme():
     with specimen('insee-IPI-2010-A21-datastructure.xml') as f:
Repository: rust-lang/rustfmt (rust)

Issue:
rustfmt removes inner attributes from inline const blocks
Clippy unfortunately warns about asserts whose conditions can be evaluated at compile-time even in inline const blocks. It's a [known issue](https://github.com/rust-lang/rust-clippy/issues/8159), it'll hopefully be solved at some point.

In the meantime, if one wishes to perform such compile-time asserts without disabling the lint globally, one can simply allow the offending lint:

```rust
fn main() {
    const {
        #![allow(clippy::assertions_on_constants)]

        assert!(1 < 2);
    }
}
```

Unfortunately, running rustfmt on the above will simply remove the attribute ([try it on the playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=cd1afc21b1eb34711d4ad0175658624f)), resulting in:

```rust
fn main() {
    const {
        assert!(1 < 2);
    }
}
```

And then Clippy nags at us again :'(

With inline const blocks due to being stabilized for 1.79 (in 6 weeks), it would be nice to fix rustfmt to not eat their code away.

### Meta

rustfmt version:
```
1.7.0-nightly (2024-05-03 d2d24e3)
```

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"WeiTheShinobi"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->

Pull request:
Fix: rustfmt should not remove inner attributes from inline const blocks
fixes #6158

`cargo test` 0 failed

first time contributed on this project🥳


Patch:
diff --git a/src/expr.rs b/src/expr.rs
index 6a21d88a..8e92ef03 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -139,7 +139,17 @@ pub(crate) fn format_expr(
         | ast::ExprKind::While(..) => to_control_flow(expr, expr_type)
             .and_then(|control_flow| control_flow.rewrite(context, shape)),
         ast::ExprKind::ConstBlock(ref anon_const) => {
-            Some(format!("const {}", anon_const.rewrite(context, shape)?))
+            let rewrite = match anon_const.value.kind {
+                ast::ExprKind::Block(ref block, opt_label) => {
+                    // Inner attributes are associated with the `ast::ExprKind::ConstBlock` node,
+                    // not the `ast::Block` node we're about to rewrite. To prevent dropping inner
+                    // attributes call `rewrite_block` directly.
+                    // See https://github.com/rust-lang/rustfmt/issues/6158
+                    rewrite_block(block, Some(&expr.attrs), opt_label, context, shape)?
+                }
+                _ => anon_const.rewrite(context, shape)?,
+            };
+            Some(format!("const {}", rewrite))
         }
         ast::ExprKind::Block(ref block, opt_label) => {
             match expr_type {


Test patch:
diff --git a/tests/target/issue_6158.rs b/tests/target/issue_6158.rs
new file mode 100644
index 00000000..82bb7d9f
--- /dev/null
+++ b/tests/target/issue_6158.rs
@@ -0,0 +1,7 @@
+fn main() {
+    const {
+        #![allow(clippy::assertions_on_constants)]
+
+        assert!(1 < 2);
+    }
+}