Skip to content

Commit dd98b4f

Browse files
authored
Merge pull request #1122 from calebshibu/py3.12-Caleb-Allen
Bug fix for Python 3.11 and over.
2 parents cd6dc9d + 3e936d3 commit dd98b4f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

suite2p/detection/stats.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dataclasses import dataclass, field
88
from warnings import warn
99

10+
import sys
1011
import numpy as np
1112
from numpy.linalg import norm
1213
from scipy.spatial import ConvexHull
@@ -26,7 +27,6 @@ def median_pix(ypix, xpix):
2627
ymed = ypix[imin]
2728
return [ymed, xmed]
2829

29-
3030
class EllipseData(NamedTuple):
3131
mu: float
3232
cov: float
@@ -47,17 +47,22 @@ def radius(self) -> float:
4747
def aspect_ratio(self) -> float:
4848
ry, rx = self.radii
4949
return aspect_ratio(width=ry, height=rx)
50-
50+
51+
def default_rsort():
52+
return np.sort(distance_kernel(radius=30).flatten())
5153

5254
@dataclass(frozen=True)
5355
class ROI:
56+
# To avoid the ValueError caused by using a mutable default value in your dataclass, you should use the default_factory argument of the field function.
5457
ypix: np.ndarray
5558
xpix: np.ndarray
5659
lam: np.ndarray
5760
med: np.ndarray
5861
do_crop: bool
59-
rsort: np.ndarray = field(default=np.sort(distance_kernel(radius=30).flatten()),
60-
repr=False)
62+
if sys.version_info >= (3, 11):
63+
rsort: np.ndarray = field(default_factory=default_rsort, repr=False)
64+
else:
65+
rsort: np.ndarray = field(default=np.sort(distance_kernel(radius=30).flatten()), repr=False)
6166

6267
def __post_init__(self):
6368
"""Validate inputs."""

0 commit comments

Comments
 (0)