diff --git a/doc/changes/devel/13310.bugfix.rst b/doc/changes/devel/13310.bugfix.rst new file mode 100644 index 00000000000..270da0ff040 --- /dev/null +++ b/doc/changes/devel/13310.bugfix.rst @@ -0,0 +1 @@ +Fix bug in :func:`mne.sys_info` where calling it in Windows could lead to a an error while trying to get the amount of available memory, by `Eric Larson`_. diff --git a/mne/_fiff/meas_info.py b/mne/_fiff/meas_info.py index c83b084d3e2..cbeccc36cab 100644 --- a/mne/_fiff/meas_info.py +++ b/mne/_fiff/meas_info.py @@ -1451,7 +1451,7 @@ class Info(ValidatedDict, SetChannelsMixin, MontageMixin, ContainsMixin): Helium level (%) after position correction. orig_file_guid : str Original file GUID. - meas_date : datetime.datetime + meas_date : datetime.datetime | None The helium level meas date. .. versionchanged:: 1.8 @@ -2884,7 +2884,7 @@ def write_meas_info(fid, info, data_type=None, reset_range=True): write_float(fid, FIFF.FIFF_HELIUM_LEVEL, hi["helium_level"]) if hi.get("orig_file_guid") is not None: write_string(fid, FIFF.FIFF_ORIG_FILE_GUID, hi["orig_file_guid"]) - if hi["meas_date"] is not None: + if hi.get("meas_date", None) is not None: write_int(fid, FIFF.FIFF_MEAS_DATE, _dt_to_stamp(hi["meas_date"])) end_block(fid, FIFF.FIFFB_HELIUM) del hi diff --git a/mne/_fiff/tests/test_meas_info.py b/mne/_fiff/tests/test_meas_info.py index 9c71bc19491..b0150d00828 100644 --- a/mne/_fiff/tests/test_meas_info.py +++ b/mne/_fiff/tests/test_meas_info.py @@ -1001,6 +1001,19 @@ def test_field_round_trip(tmp_path): assert_object_equal(info, info_read) with pytest.raises(TypeError, match="datetime"): info["helium_info"]["meas_date"] = (1, 2) + # should allow it to be None, though (checking gh-13154) + info["helium_info"]["meas_date"] = None + info.save(fname, overwrite=True) + info_read = read_info(fname) + assert_object_equal(info, info_read) + assert info_read["helium_info"]["meas_date"] is None + # not 100% sure how someone could end up with it deleted, but should still be + # writeable + del info["helium_info"]["meas_date"] + info.save(fname, overwrite=True) + info_read = read_info(fname) + info["helium_info"]["meas_date"] = None # we always set it (which is reasonable) + assert_object_equal(info, info_read) def test_equalize_channels(): diff --git a/mne/utils/config.py b/mne/utils/config.py index c2f3408b427..3500358a38c 100644 --- a/mne/utils/config.py +++ b/mne/utils/config.py @@ -687,7 +687,12 @@ def _get_total_memory(): "(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory", ] ).decode() - total_memory = int(o) + # Can get for example a "running scripts is disabled on this system" + # error where "o" will be a long string rather than an int + try: + total_memory = int(o) + except Exception: # pragma: no cover + total_memory = 0 elif platform.system() == "Linux": o = subprocess.check_output(["free", "-b"]).decode() total_memory = int(o.splitlines()[1].split()[1])