| 17 | |
| 18 | |
| 19 | class Timeseries(PartitionsFiltered, BlockwiseIO): |
| 20 | _absorb_projections = True |
| 21 | |
| 22 | _parameters = [ |
| 23 | "start", |
| 24 | "end", |
| 25 | "dtypes", |
| 26 | "freq", |
| 27 | "partition_freq", |
| 28 | "seed", |
| 29 | "kwargs", |
| 30 | "columns", |
| 31 | "_partitions", |
| 32 | "_series", |
| 33 | ] |
| 34 | _defaults = { |
| 35 | "start": "2000-01-01", |
| 36 | "end": "2000-01-31", |
| 37 | "dtypes": {"name": "string", "id": int, "x": float, "y": float}, |
| 38 | "freq": "1s", |
| 39 | "partition_freq": "1d", |
| 40 | "seed": None, |
| 41 | "kwargs": {}, |
| 42 | "_partitions": None, |
| 43 | "_series": False, |
| 44 | } |
| 45 | |
| 46 | @functools.cached_property |
| 47 | def _meta(self): |
| 48 | result = self._make_timeseries_part("2000", "2000", 0).iloc[:0] |
| 49 | if self._series: |
| 50 | return result[result.columns[0]] |
| 51 | return result |
| 52 | |
| 53 | def _divisions(self): |
| 54 | return pd.date_range(start=self.start, end=self.end, freq=self.partition_freq) |
| 55 | |
| 56 | @property |
| 57 | def _dtypes(self): |
| 58 | dtypes = self.operand("dtypes") |
| 59 | return {col: dtypes[col] for col in self.operand("columns")} |
| 60 | |
| 61 | @functools.cached_property |
| 62 | def random_state(self): |
| 63 | npartitions = len(self._divisions()) - 1 |
| 64 | ndtypes = max(len(self.operand("dtypes")), 1) |
| 65 | random_state = np.random.RandomState(self.seed) |
| 66 | n = npartitions * ndtypes |
| 67 | random_data = random_state.bytes(n * 4) # `n` 32-bit integers |
| 68 | l = list(np.frombuffer(random_data, dtype=np.uint32).reshape((n,))) |
| 69 | assert len(l) == n |
| 70 | return l |
| 71 | |
| 72 | @functools.cached_property |
| 73 | def _make_timeseries_part(self): |
| 74 | return MakeTimeseriesPart( |
| 75 | self.operand("dtypes"), |
| 76 | list(self._dtypes.keys()), |