MCPcopy Create free account
hub / github.com/kernc/backtesting.py / arr2shm

Method arr2shm

backtesting/_util.py:304–313  ·  view source on GitHub ↗

Array to shared memory. Returns (shm_name, shape, dtype) used for restore.

(self, vals)

Source from the content-addressed store, hash-verified

302 raise
303
304 def arr2shm(self, vals):
305 """Array to shared memory. Returns (shm_name, shape, dtype) used for restore."""
306 assert vals.ndim == 1, (vals.ndim, vals.shape, vals)
307 shm = self.SharedMemory(size=vals.nbytes, create=True)
308 # np.array can't handle pandas' tz-aware datetimes
309 # https://github.com/numpy/numpy/issues/18279
310 buf = np.ndarray(vals.shape, dtype=vals.dtype.base, buffer=shm.buf)
311 has_tz = getattr(vals.dtype, 'tz', None)
312 buf[:] = vals.tz_localize(None) if has_tz else vals # Copy into shared memory
313 return shm.name, vals.shape, vals.dtype
314
315 def df2shm(self, df):
316 return tuple((

Callers 1

df2shmMethod · 0.95

Calls 1

SharedMemoryMethod · 0.95

Tested by

no test coverage detected