Skip to content

Commit

Permalink
ENH load.unpickle(): handle numpy backwards bug
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbrodbeck committed Jan 28, 2025
1 parent 7fd8047 commit 1c9f8de
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions eelbrain/_io/pickle.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# Author: Christian Brodbeck <christianbrodbeck@nyu.edu>
from packaging.version import Version
from pathlib import Path
from pickle import dump, HIGHEST_PROTOCOL, Unpickler
from itertools import chain
import os
from typing import Any

import numpy

from .._data_obj import Dataset, NDVar, Var, SourceSpaceBase, ismodelobject
from .._types import PathArg
from .._utils import IS_WINDOWS, tqdm, ui


NUMPY_1 = Version(numpy.__version__) < Version('2')


class EelUnpickler(Unpickler):

def find_class(self, module, name):
Expand All @@ -31,6 +37,9 @@ def find_class(self, module, name):
elif module.startswith('pathlib'):
if name == 'WindowsPath' and not IS_WINDOWS:
name = 'Path'
elif NUMPY_1 and module.startswith('numpy._core.numeric'):
# This affected some pickles created with numpy 2
module = module.replace('numpy._core.numeric', 'numpy.core.numeric')

return Unpickler.find_class(self, module, name)

Expand Down

0 comments on commit 1c9f8de

Please sign in to comment.