File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,16 @@ def __array_finalize__(self, obj):
5656 self .name = getattr (obj , 'name' , '' )
5757 self ._opts = getattr (obj , '_opts' , {})
5858
59+ # Make sure properties name and _opts are carried over
60+ # when (un-)pickling.
61+ def __reduce__ (self ):
62+ value = super ().__reduce__ ()
63+ return value [:2 ] + (value [2 ] + (self .__dict__ ,),)
64+
65+ def __setstate__ (self , state ):
66+ self .__dict__ .update (state [- 1 ])
67+ super ().__setstate__ (state [:- 1 ])
68+
5969 def __bool__ (self ):
6070 try :
6171 return bool (self [- 1 ])
Original file line number Diff line number Diff line change 44import time
55import unittest
66import warnings
7+ from concurrent .futures .process import ProcessPoolExecutor
78from contextlib import contextmanager
89from glob import glob
910from runpy import run_path
@@ -899,6 +900,11 @@ def next(self):
899900
900901 Backtest (GOOG .iloc [:20 ], S ).run ()
901902
903+ def test_indicators_picklable (self ):
904+ with ProcessPoolExecutor () as executor :
905+ stats = executor .submit (Backtest .run , Backtest (SHORT_DATA , SmaCross )).result ()
906+ assert stats ._strategy ._indicators [0 ]._opts , '._opts and .name were not unpickled'
907+
902908
903909class TestDocs (TestCase ):
904910 DOCS_DIR = os .path .join (os .path .dirname (__file__ ), '..' , '..' , 'doc' )
You canβt perform that action at this time.
0 commit comments