Skip to content

CircuitsMatroid: check for empty dict before min#41254

Merged
vbraun merged 1 commit intosagemath:developfrom
gmou3:circuits_matroid_empty_min
Dec 21, 2025
Merged

CircuitsMatroid: check for empty dict before min#41254
vbraun merged 1 commit intosagemath:developfrom
gmou3:circuits_matroid_empty_min

Conversation

@gmou3
Copy link
Copy Markdown
Contributor

@gmou3 gmou3 commented Dec 3, 2025

This was already working as intented (confusingly), probably due to some Cython optimization which avoided the min on an empty dict. I added the check for clarity and robustness.

For example, this calls min on an empty dict:

sage: from sage.matroids.circuits_matroid import CircuitsMatroid
sage: M = matroids.Uniform(5, 5)
sage: CM = CircuitsMatroid(M)
sage: CM.dependent_sets(2)
SetSystem of 0 sets over 5 elements

The addition of a print(min(self._k_C)) makes the issue clear, as it raises:

ValueError: min() iterable argument is empty

This was already working as intented (confusingly), probably due to some Cython optimization which avoided the min on an empty dict.
I added the check for clarity and robustness.

For example, this calls min on an empty dict:
```python
sage: from sage.matroids.circuits_matroid import CircuitsMatroid
sage: M = matroids.Uniform(5, 5)
sage: CM = CircuitsMatroid(M)
sage: CM.dependent_sets(2)
SetSystem of 0 sets over 5 elements
```

The addition of a `print(min(self._k_C))` makes the issue clear, as it raises:
```
ValueError: min() iterable argument is empty
```
Copy link
Copy Markdown
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 20, 2025
sagemathgh-41254: `CircuitsMatroid`: check for empty dict before min
    
This was already working as intented (confusingly), probably due to some
Cython optimization which avoided the min on an empty dict. I added the
check for clarity and robustness.

For example, this calls min on an empty dict:
```python
sage: from sage.matroids.circuits_matroid import CircuitsMatroid
sage: M = matroids.Uniform(5, 5)
sage: CM = CircuitsMatroid(M)
sage: CM.dependent_sets(2)
SetSystem of 0 sets over 5 elements
```

The addition of a `print(min(self._k_C))` makes the issue clear, as it
raises:
```
ValueError: min() iterable argument is empty
```
    
URL: sagemath#41254
Reported by: gmou3
Reviewer(s): Travis Scrimshaw
@vbraun vbraun merged commit e58c19b into sagemath:develop Dec 21, 2025
23 of 25 checks passed
@gmou3 gmou3 deleted the circuits_matroid_empty_min branch January 31, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants