Skip to content

Commit bcd6ec7

Browse files
committed
update test suites
1 parent 5ca6cb6 commit bcd6ec7

File tree

4 files changed

+275
-472
lines changed

4 files changed

+275
-472
lines changed

PyFin/Analysis/TechnicalAnalysis/StatefulTechnicalAnalysers.pyx

+52-81
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ cdef class SecuritySingleValueHolder(SecurityValueHolder):
4545
else:
4646
self._holderTemplate = HolderType(window=window, dependency=self._dependency)
4747

48+
def __setstate__(self, state):
49+
self.copy_attributes(state, is_deep=False)
50+
4851

4952
cdef class SecurityMovingAverage(SecuritySingleValueHolder):
5053
def __init__(self, window, dependency='x'):
@@ -66,9 +69,6 @@ cdef class SecurityMovingAverage(SecuritySingleValueHolder):
6669
else:
6770
return SecurityMovingAverage, (self._window, self._dependency), d
6871

69-
def __setstate__(self, state):
70-
self.copy_attributes(state, is_deep=False)
71-
7272

7373
cdef class SecurityMovingMax(SecuritySingleValueHolder):
7474
def __init__(self, window, dependency='x'):
@@ -89,9 +89,6 @@ cdef class SecurityMovingMax(SecuritySingleValueHolder):
8989
else:
9090
return SecurityMovingMax, (self._window, self._dependency), d
9191

92-
def __setstate__(self, state):
93-
self.copy_attributes(state, is_deep=False)
94-
9592

9693
cdef class SecurityMovingMinimum(SecuritySingleValueHolder):
9794
def __init__(self, window, dependency='x'):
@@ -112,9 +109,6 @@ cdef class SecurityMovingMinimum(SecuritySingleValueHolder):
112109
else:
113110
return SecurityMovingMinimum, (self._window, self._dependency), d
114111

115-
def __setstate__(self, state):
116-
self.copy_attributes(state, is_deep=False)
117-
118112

119113
cdef class SecurityMovingQuantile(SecuritySingleValueHolder):
120114
def __init__(self, window, dependency='x'):
@@ -135,9 +129,6 @@ cdef class SecurityMovingQuantile(SecuritySingleValueHolder):
135129
else:
136130
return SecurityMovingQuantile, (self._window, self._dependency), d
137131

138-
def __setstate__(self, state):
139-
self.copy_attributes(state, is_deep=False)
140-
141132

142133
cdef class SecurityMovingAllTrue(SecuritySingleValueHolder):
143134
def __init__(self, window, dependency='x'):
@@ -158,9 +149,6 @@ cdef class SecurityMovingAllTrue(SecuritySingleValueHolder):
158149
else:
159150
return SecurityMovingAllTrue, (self._window, self._dependency), d
160151

161-
def __setstate__(self, state):
162-
self.copy_attributes(state, is_deep=False)
163-
164152

165153
cdef class SecurityMovingAnyTrue(SecuritySingleValueHolder):
166154
def __init__(self, window, dependency='x'):
@@ -181,9 +169,6 @@ cdef class SecurityMovingAnyTrue(SecuritySingleValueHolder):
181169
else:
182170
return SecurityMovingAnyTrue, (self._window, self._dependency), d
183171

184-
def __setstate__(self, state):
185-
self.copy_attributes(state, is_deep=False)
186-
187172

188173
cdef class SecurityMovingSum(SecuritySingleValueHolder):
189174
def __init__(self, window, dependency='x'):
@@ -204,30 +189,26 @@ cdef class SecurityMovingSum(SecuritySingleValueHolder):
204189
else:
205190
return SecurityMovingSum, (self._window, self._dependency), d
206191

207-
def __setstate__(self, state):
208-
self.copy_attributes(state, is_deep=False)
209-
210192

211193
cdef class SecurityMovingVariance(SecuritySingleValueHolder):
212194
def __init__(self, window, dependency='x'):
213195
super(SecurityMovingVariance, self).__init__(window, MovingVariance, dependency)
214196

215197
def __deepcopy__(self, memo):
216198
if self._compHolder:
217-
return SecurityMovingVariance(self._window - self._compHolder._window, self._compHolder)
199+
copied = SecurityMovingVariance(self._window - self._compHolder._window, self._compHolder)
218200
else:
219-
return SecurityMovingVariance(self._window, self._dependency)
201+
copied = SecurityMovingVariance(self._window, self._dependency)
202+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
203+
return copied
220204

221205
def __reduce__(self):
222-
d = {}
206+
d = self.collect_attributes()
223207
if self._compHolder:
224208
return SecurityMovingVariance, (self._window - self._compHolder._window, self._compHolder), d
225209
else:
226210
return SecurityMovingVariance, (self._window, self._dependency), d
227211

228-
def __setstate__(self, state):
229-
pass
230-
231212

232213
cdef class SecurityMovingStandardDeviation(SecuritySingleValueHolder):
233214
def __init__(self, window, dependency='x'):
@@ -249,177 +230,170 @@ cdef class SecurityMovingStandardDeviation(SecuritySingleValueHolder):
249230
else:
250231
return SecurityMovingStandardDeviation, (self._window, self._dependency), d
251232

252-
def __setstate__(self, state):
253-
self.copy_attributes(state, is_deep=False)
254-
255233

256234
cdef class SecurityMovingCountedPositive(SecuritySingleValueHolder):
257235
def __init__(self, window, dependency='x'):
258236
super(SecurityMovingCountedPositive, self).__init__(window, MovingCountedPositive, dependency)
259237

260238
def __deepcopy__(self, memo):
261239
if self._compHolder:
262-
return SecurityMovingCountedPositive(self._window - self._compHolder._window, self._compHolder)
240+
copied = SecurityMovingCountedPositive(self._window - self._compHolder._window, self._compHolder)
263241
else:
264-
return SecurityMovingCountedPositive(self._window, self._dependency)
242+
copied = SecurityMovingCountedPositive(self._window, self._dependency)
243+
244+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
245+
return copied
265246

266247
def __reduce__(self):
267-
d = {}
248+
d = self.collect_attributes()
268249
if self._compHolder:
269250
return SecurityMovingCountedPositive, (self._window - self._compHolder._window, self._compHolder), d
270251
else:
271252
return SecurityMovingCountedPositive, (self._window, self._dependency), d
272253

273-
def __setstate__(self, state):
274-
pass
275-
276254

277255
cdef class SecurityMovingPositiveAverage(SecuritySingleValueHolder):
278256
def __init__(self, window, dependency='x'):
279257
super(SecurityMovingPositiveAverage, self).__init__(window, MovingPositiveAverage, dependency)
280258

281259
def __deepcopy__(self, memo):
282260
if self._compHolder:
283-
return SecurityMovingPositiveAverage(self._window - self._compHolder._window, self._compHolder)
261+
copied = SecurityMovingPositiveAverage(self._window - self._compHolder._window, self._compHolder)
284262
else:
285-
return SecurityMovingPositiveAverage(self._window, self._dependency)
263+
copied = SecurityMovingPositiveAverage(self._window, self._dependency)
264+
265+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
266+
return copied
286267

287268
def __reduce__(self):
288-
d = {}
269+
d = self.collect_attributes()
289270
if self._compHolder:
290271
return SecurityMovingPositiveAverage, (self._window - self._compHolder._window, self._compHolder), d
291272
else:
292273
return SecurityMovingPositiveAverage, (self._window, self._dependency), d
293274

294-
def __setstate__(self, state):
295-
pass
296-
297275

298276
cdef class SecurityMovingCountedNegative(SecuritySingleValueHolder):
299277
def __init__(self, window, dependency='x'):
300278
super(SecurityMovingCountedNegative, self).__init__(window, MovingCountedNegative, dependency)
301279

302280
def __deepcopy__(self, memo):
303281
if self._compHolder:
304-
return SecurityMovingCountedNegative(self._window - self._compHolder._window, self._compHolder)
282+
copied = SecurityMovingCountedNegative(self._window - self._compHolder._window, self._compHolder)
305283
else:
306-
return SecurityMovingCountedNegative(self._window, self._dependency)
284+
copied = SecurityMovingCountedNegative(self._window, self._dependency)
285+
286+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
287+
return copied
307288

308289
def __reduce__(self):
309-
d = {}
290+
d = self.collect_attributes()
310291
if self._compHolder:
311292
return SecurityMovingCountedNegative, (self._window - self._compHolder._window, self._compHolder), d
312293
else:
313294
return SecurityMovingCountedNegative, (self._window, self._dependency), d
314295

315-
def __setstate__(self, state):
316-
pass
317-
318296

319297
cdef class SecurityMovingNegativeAverage(SecuritySingleValueHolder):
320298
def __init__(self, window, dependency='x'):
321299
super(SecurityMovingNegativeAverage, self).__init__(window, MovingNegativeAverage, dependency)
322300

323301
def __deepcopy__(self, memo):
324302
if self._compHolder:
325-
return SecurityMovingNegativeAverage(self._window - self._compHolder._window, self._compHolder)
303+
copied = SecurityMovingNegativeAverage(self._window - self._compHolder._window, self._compHolder)
326304
else:
327-
return SecurityMovingNegativeAverage(self._window, self._dependency)
305+
copied = SecurityMovingNegativeAverage(self._window, self._dependency)
306+
307+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
308+
return copied
328309

329310
def __reduce__(self):
330-
d = {}
311+
d = self.collect_attributes()
331312
if self._compHolder:
332313
return SecurityMovingNegativeAverage, (self._window - self._compHolder._window, self._compHolder), d
333314
else:
334315
return SecurityMovingNegativeAverage, (self._window, self._dependency), d
335316

336-
def __setstate__(self, state):
337-
pass
338-
339317

340318
cdef class SecurityMovingPositiveDifferenceAverage(SecuritySingleValueHolder):
341319
def __init__(self, window, dependency='x'):
342320
super(SecurityMovingPositiveDifferenceAverage, self).__init__(window, MovingPositiveDifferenceAverage, dependency)
343321

344322
def __deepcopy__(self, memo):
345323
if self._compHolder:
346-
return SecurityMovingPositiveDifferenceAverage(self._window - self._compHolder._window, self._compHolder)
324+
copied = SecurityMovingPositiveDifferenceAverage(self._window - self._compHolder._window, self._compHolder)
347325
else:
348-
return SecurityMovingPositiveDifferenceAverage(self._window, self._dependency)
326+
copied = SecurityMovingPositiveDifferenceAverage(self._window, self._dependency)
327+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
328+
return copied
349329

350330
def __reduce__(self):
351-
d = {}
331+
d = self.collect_attributes()
352332
if self._compHolder:
353333
return SecurityMovingPositiveDifferenceAverage, (self._window - self._compHolder._window, self._compHolder), d
354334
else:
355335
return SecurityMovingPositiveDifferenceAverage, (self._window, self._dependency), d
356336

357-
def __setstate__(self, state):
358-
pass
359-
360337

361338
cdef class SecurityMovingNegativeDifferenceAverage(SecuritySingleValueHolder):
362339
def __init__(self, window, dependency='x'):
363340
super(SecurityMovingNegativeDifferenceAverage, self).__init__(window, MovingNegativeDifferenceAverage, dependency)
364341

365342
def __deepcopy__(self, memo):
366343
if self._compHolder:
367-
return SecurityMovingNegativeDifferenceAverage(self._window - self._compHolder._window, self._compHolder)
344+
copied = SecurityMovingNegativeDifferenceAverage(self._window - self._compHolder._window, self._compHolder)
368345
else:
369-
return SecurityMovingNegativeDifferenceAverage(self._window, self._dependency)
346+
copied = SecurityMovingNegativeDifferenceAverage(self._window, self._dependency)
347+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
348+
return copied
370349

371350
def __reduce__(self):
372-
d = {}
351+
d = self.collect_attributes()
373352
if self._compHolder:
374353
return SecurityMovingNegativeDifferenceAverage, (self._window - self._compHolder._window, self._compHolder), d
375354
else:
376355
return SecurityMovingNegativeDifferenceAverage, (self._window, self._dependency), d
377356

378-
def __setstate__(self, state):
379-
pass
380-
381357

382358
cdef class SecurityMovingRSI(SecuritySingleValueHolder):
383359
def __init__(self, window, dependency='x'):
384360
super(SecurityMovingRSI, self).__init__(window, MovingRSI, dependency)
385361

386362
def __deepcopy__(self, memo):
387363
if self._compHolder:
388-
return SecurityMovingRSI(self._window - self._compHolder._window, self._compHolder)
364+
copied = SecurityMovingRSI(self._window - self._compHolder._window, self._compHolder)
389365
else:
390-
return SecurityMovingRSI(self._window, self._dependency)
366+
copied = SecurityMovingRSI(self._window, self._dependency)
367+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
368+
return copied
391369

392370
def __reduce__(self):
393-
d = {}
371+
d = self.collect_attributes()
394372
if self._compHolder:
395373
return SecurityMovingRSI, (self._window - self._compHolder._window, self._compHolder), d
396374
else:
397375
return SecurityMovingRSI, (self._window, self._dependency), d
398376

399-
def __setstate__(self, state):
400-
pass
401-
402377

403378
cdef class SecurityMovingLogReturn(SecuritySingleValueHolder):
404379
def __init__(self, window, dependency='x'):
405380
super(SecurityMovingLogReturn, self).__init__(window, MovingLogReturn, dependency)
406381

407382
def __deepcopy__(self, memo):
408383
if self._compHolder:
409-
return SecurityMovingLogReturn(self._window - self._compHolder._window, self._compHolder)
384+
copied = SecurityMovingLogReturn(self._window - self._compHolder._window, self._compHolder)
410385
else:
411-
return SecurityMovingLogReturn(self._window, self._dependency)
386+
copied = SecurityMovingLogReturn(self._window, self._dependency)
387+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
388+
return copied
412389

413390
def __reduce__(self):
414-
d = {}
391+
d = self.collect_attributes()
415392
if self._compHolder:
416393
return SecurityMovingLogReturn, (self._window - self._compHolder._window, self._compHolder), d
417394
else:
418395
return SecurityMovingLogReturn, (self._window, self._dependency), d
419396

420-
def __setstate__(self, state):
421-
pass
422-
423397

424398
cdef class SecurityMovingHistoricalWindow(SecuritySingleValueHolder):
425399
def __init__(self, window, dependency='x'):
@@ -506,6 +480,3 @@ cdef class SecurityMovingHistoricalWindow(SecuritySingleValueHolder):
506480
return SecurityMovingHistoricalWindow,(self._window - self._compHolder._window, self._compHolder), d
507481
else:
508482
return SecurityMovingHistoricalWindow, (self._window, self._dependency), d
509-
510-
def __setstate__(self, state):
511-
self.copy_attributes(state, is_deep=False)

PyFin/Math/Accumulators/StatelessAccumulators.pyx

+28-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,20 @@ cdef class PositivePart(StatelessSingleValueAccumulator):
148148
return self._pos
149149

150150
def __deepcopy__(self, memo):
151-
return PositivePart(self._dependency)
151+
copied = PositivePart(self._dependency)
152+
153+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
154+
copied._pos = self._pos
155+
return copied
156+
157+
def __reduce__(self):
158+
d = self.collect_attributes()
159+
d['_pos'] = self._pos
160+
return PositivePart, (self._dependency,), d
161+
162+
def __setstate__(self, state):
163+
self.copy_attributes(state, is_deep=False)
164+
self._pos = state['_pos']
152165

153166

154167
cdef class NegativePart(StatelessSingleValueAccumulator):
@@ -172,7 +185,20 @@ cdef class NegativePart(StatelessSingleValueAccumulator):
172185
return self._neg
173186

174187
def __deepcopy__(self, memo):
175-
return NegativePart(self._dependency)
188+
copied = NegativePart(self._dependency)
189+
190+
copied.copy_attributes(self.collect_attributes(), is_deep=True)
191+
copied._neg = self._neg
192+
return copied
193+
194+
def __reduce__(self):
195+
d = self.collect_attributes()
196+
d['_neg'] = self._neg
197+
return NegativePart, (self._dependency,), d
198+
199+
def __setstate__(self, state):
200+
self.copy_attributes(state, is_deep=False)
201+
self._neg = state['_neg']
176202

177203

178204
cdef class Max(StatelessSingleValueAccumulator):

0 commit comments

Comments
 (0)