Skip to content

Some mcmc stacking functions broken in Python 3.11 #82

Description

@bmcguir2

Attempting to run in Python 3.11 produces the following errors:

`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File /Users/Brett/Dropbox/Programs/molsim/ipython_quickstart.py:5
2 sys.path.insert(0, '/Users/Brett/Dropbox/Programs')
4 import numpy as np
----> 5 from molsim.file_handling import load_mol, load_obs, load_multi_obs
6 from molsim.file_io import _write_xy
7 from molsim.constants import ccm, cm, ckm, h, k, kcm

File /Users/Brett/Dropbox/Programs/molsim/molsim/init.py:20
18 from . import analysis
19 from . import mcmc
---> 20 from . import stack

File /Users/Brett/Dropbox/Programs/molsim/molsim/stack.py:118
112 for index in range(4):
113 self._components.append(
114 StackComponent(source_sizes[index], dv, vlsrs[index], tex, ncols[index])
115 )
--> 118 @DataClass
119 class SpectrumChunk:
120 frequency: np.ndarray
121 _intensity: np.ndarray

File ~/miniconda3/lib/python3.11/dataclasses.py:1230, in dataclass(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots, weakref_slot)
1227 return wrap
1229 # We're called as @DataClass without parens.
-> 1230 return wrap(cls)

File ~/miniconda3/lib/python3.11/dataclasses.py:1220, in dataclass..wrap(cls)
1219 def wrap(cls):
-> 1220 return _process_class(cls, init, repr, eq, order, unsafe_hash,
1221 frozen, match_args, kw_only, slots,
1222 weakref_slot)

File ~/miniconda3/lib/python3.11/dataclasses.py:958, in _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots, weakref_slot)
955 kw_only = True
956 else:
957 # Otherwise it's a field of some type.
--> 958 cls_fields.append(_get_field(cls, name, type, kw_only))
960 for f in cls_fields:
961 fields[f.name] = f

File ~/miniconda3/lib/python3.11/dataclasses.py:815, in _get_field(cls, a_name, a_type, default_kw_only)
811 # For real fields, disallow mutable defaults. Use unhashable as a proxy
812 # indicator for mutability. Read the hash attribute from the class,
813 # not the instance.
814 if f._field_type is _FIELD and f.default.class.hash is None:
--> 815 raise ValueError(f'mutable default {type(f.default)} for field '
816 f'{f.name} is not allowed: use default_factory')
818 return f

ValueError: mutable default <class 'numpy.ndarray'> for field _mask is not allowed: use default_factory`

This appears to be a known issue with no resolution that I can find: huggingface/datasets#5230

Downgrading to Python 3.9 works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions