From ab641ed7b0c1edde76efccbb22febf2fdc6d8f3e Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Mon, 7 Nov 2016 13:19:52 -0500 Subject: more precise pickling --- pyisda/curve.pyx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index ef11a42..e2e602e 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -166,9 +166,22 @@ cdef class YieldCurve(Curve): ) def __dealloc__(self): + ## __dealloc__ of superclass is called by cython so no need to call here if self._dates is not NULL: free(self._dates) + def __getstate__(self): + cdef Py_ssize_t size = sizeof(TRatePt) * self._ninstr + cdef bytes dates = (self._dates)[:size] + return super().__getstate__() + (self._ninstr, dates) + + def __setstate__(self, state): + super().__setstate__(state[:5]) + self._ninstr = state[5] + cdef Py_ssize_t size = sizeof(TRatePt) * self._ninstr + self._dates = malloc(size) + memcpy(self._dates, state[6], size) + @classmethod def from_discount_factors(cls, base_date, list dates, double[:] dfs, str day_count_conv): """ build a yield curve from a list of discount factors """ @@ -189,7 +202,8 @@ cdef class YieldCurve(Curve): discount_factor = Curve.__forward_zero_price - def list_dates(self): + @property + def dates(self): """ returns the list of instrument dates """ -- cgit v1.2.3-70-g09d2