Reads a Statistics object from the CSV file at the given filesystem location. Parameters ---------- where Filesystem location to read from. delimiter Value separator. Default comma. kwargs Additional keywor
(cls, where: Path | str, delimiter: str = ",", **kwargs)
| 104 | |
| 105 | @classmethod |
| 106 | def from_csv(cls, where: Path | str, delimiter: str = ",", **kwargs): |
| 107 | """ |
| 108 | Reads a Statistics object from the CSV file at the given filesystem |
| 109 | location. |
| 110 | |
| 111 | Parameters |
| 112 | ---------- |
| 113 | where |
| 114 | Filesystem location to read from. |
| 115 | delimiter |
| 116 | Value separator. Default comma. |
| 117 | kwargs |
| 118 | Additional keyword arguments. These are passed to |
| 119 | :class:`csv.DictReader`. |
| 120 | |
| 121 | Returns |
| 122 | ------- |
| 123 | Statistics |
| 124 | Statistics object populated with the data read from the given |
| 125 | filesystem location. |
| 126 | """ |
| 127 | field2type = {field.name: field.type for field in fields(_Datum)} |
| 128 | |
| 129 | def make_datum(row) -> _Datum: |
| 130 | datum = {} |
| 131 | |
| 132 | for name, value in row.items(): |
| 133 | if name in field2type: |
| 134 | if field2type[name] is bool: |
| 135 | datum[name] = bool(int(value)) |
| 136 | else: |
| 137 | datum[name] = field2type[name](value) # type: ignore |
| 138 | |
| 139 | return _Datum(**datum) |
| 140 | |
| 141 | with open(where) as fh: |
| 142 | lines = fh.readlines() |
| 143 | |
| 144 | stats = cls() |
| 145 | |
| 146 | for row in csv.DictReader(lines, delimiter=delimiter, **kwargs): |
| 147 | stats.runtimes.append(float(row["runtime"])) |
| 148 | stats.num_iterations += 1 |
| 149 | stats.data.append(make_datum(row)) |
| 150 | |
| 151 | return stats |
| 152 | |
| 153 | def to_csv( |
| 154 | self, |