Skip to content

Cannot unpickle file created by NumPy 2.x in NumPy 1.x #28340

@ngoldbaum

Description

@ngoldbaum

Originally posted by @gg4u in #24844

I will post a test code you can reproduce below.
You can find the audio file in the zip folder (note that the pickle in the zip was created with numpy 2.0.0)

## LOAD PICKLE => error if numpy 1.26.4
import pickle
from numpy._core.multiarray import _reconstruct


with open(f'./data/test_segments_raw.pkl','rb') as f:
    all_segments = pickle.load(f)


---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[4], line 8
      5 DS_FILENAME = 'Bat_'+str(emitter)
      7 with open(f'./data/{DS_FILENAME}_all_segments_raw.pkl','rb') as f:
----> 8     all_segments = pickle.load(f)

ModuleNotFoundError: No module named 'numpy._core.numeric'

Here's another version for you to run the code

try with one wav file in attachment, loading it with numpy >= 2, and save it as a pickle.
then, try to load that pickle file with numpy 1.26.4

## SAVE PICKLE => try to save it with numpy >= 2
import librosa
import pickle

# see the file in the archive

[Archive.zip](https://github.com/user-attachments/files/18799307/Archive.zip)

data, rate = librosa.core.load('121004165931143478.WAV')

import numpy as np
segments = np.array(list(zip([35795.0, 210795.0], [71747.0, 242041.0])))

def process_audio_segments(audio, time):
    return audio[int(time[0]): int(time[1])]

all_segments = []
for s in segments:
    all_segments.append(process_audio_segments(data, s))
        
with open(f'./data/test_segments_raw.pkl','wb') as f:
    pickle.dump(all_segments, f, protocol=pickle.HIGHEST_PROTOCOL)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions