I’ve been playing around with GitPython recently, in an effort to analyse the relation between commits and software quality.
One by-product of this analysis was a Pandas Series of the number of commits on a given day. Since this turned out to be a time-consuming operation (as I needed to repoint head back in time for each day I was interested in), I opted to pickle the Series. Imagine the horror when, the day after I had run the script, I discovered that unpickling the data raised an exception.
In : commits = pd.read_pickle('commits.pkl')
TypeError: __init__() takes at least 2 arguments (1 given)
That error comes from
pickle_compat.py, part of the Pandas library.
However, no mention is made of which class actually raised it.
%debug and going up and down the stack didn’t reveal much either, so I decided to go closer to the actual unpickling operation, using cPickle.
In : commits = cPickle.load(open('commits.pkl'))
TypeError: ('__init__() takes at least 2 arguments (1 given)', <class 'git.objects.util.tzoffset'>, ())
Still an error, but a more meaningful one. Let’s see what a brief inspection of
In : import git.objects.util
In : git.objects.util.tzoffset?
Init signature: git.objects.util.tzoffset(self, secs_west_of_utc, name=None)
__init__ expects a
secs_west_of_utc positional argument (no default).
To still be able to unpickle your data without the need for running the script again, you just need to mock that class with a slightly modified one. Thank partial applications for that.
In : git.objects.util.tzoffset = partial(git.objects.util.tzoffset, secs_west_of_utc=0)
In : commits = pickle.load(open('commits.pkl'))
Job done – thank you functools!