Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.12 Compatibility Issue #1159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

fdeguire03
Copy link

@fdeguire03 fdeguire03 commented Jan 29, 2025

Summary

This PR updates the rsort field definitions in suite2p/detection/stats.py to replace mutable default values with default_factory. As of Python 3.12, dataclass enforces that default fields cannot be mutable type, so it is not currently possible to run suite2p in Python 3.12 or newer. Implementing this change ensures compatibility with Python 3.12 and prevents unintended shared state across instances.

Changes

Updated rsort in suite2p/detection/stats.py to use default_factory = lambda: np.sort(distance_kernel(radius=30).flatten()) instead of default=np.sort(distance_kernel(radius=30).flatten()).

Verified compatibility with Python 3.12, which now enforces stricter checks on mutable defaults. Also verified backward compatibility with Python 3.9. The default_factor parameter was introduced in Python 3.7 with the dataclasses module, so implementation of this pull request will not affect any previous versions of Python that are able to run suite2p.

Reasoning

Python 3.12 introduced a stricter enforcement of mutable defaults in dataclass fields, raising a ValueError when using a mutable default directly. This fix ensures proper instance-level initialization while maintaining the intended behavior.

Testing

Verified that the updated implementation runs correctly without ValueError in Python 3.12.

@fdeguire03 fdeguire03 changed the title Fix mutable default value in suite2p.detection.stats.py Python 3.12 Compatibility Issue Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant