예제 #1
0
    def _data_target(self, s):
        s = s.replace("?", '"nan"')

        values = json.loads(f"[{s}]")
        assert (
            values
        ), "A given series should contains a set of comma separated numeric values. At least one numeric value should be there in a series. Missing values should be indicated with ? symbol"

        return np.array(values, dtype=float)
예제 #2
0
파일: jsonl.py 프로젝트: Schmedu/gluon-ts
    def __iter__(self):
        # Basic idea is to split the dataset into roughly equally sized segments
        # with lower and upper bound, where each worker is assigned one segment
        bounds = get_bounds_for_mp_data_loading(len(self))
        if not self.cache or (self.cache and not self._data_cache):
            with self.open(self.path) as jsonl_file:
                for line_number, raw in enumerate(jsonl_file):
                    if not bounds.lower <= line_number < bounds.upper:
                        continue

                    span = Span(path=self.path, line=line_number)
                    try:
                        parsed_line = Line(json.loads(raw), span=span)
                        if self.cache:
                            self._data_cache.append(parsed_line)
                        yield parsed_line
                    except ValueError:
                        raise GluonTSDataError(
                            f"Could not read json line {line_number}, {raw}")
        else:
            yield from self._data_cache
예제 #3
0
파일: jsonl.py 프로젝트: Schmedu/gluon-ts
def load(file_obj):
    for line in file_obj:
        yield json.loads(line)
예제 #4
0
def load_json(path: Path, freq: str) -> Iterator[Any]:
    for file in find_files(path, FileDataset.is_valid):
        for line in open(file):
            yield json.loads(line)