Beispiel #1
0
    def extract_csvs(self, zipf: ZipFile) -> MovieLensDataSet:
        dataset = MovieLensDataSet()
        valid_stems = set(dataset.__annotations__)

        for info in zipf.filelist:
            path = Path(zipf, at=info.filename)

            if path.name.endswith('.csv') and (stem := path.name[:-len('.csv')]) in valid_stems:
                setattr(dataset, stem, path.open('r', encoding='utf-8'))
def _copy_file_from_zip(zfp: zipfile.Path, p: Path) -> None:
    with p.open("wb") as writer:
        if sys.version_info >= (3, 9):
            # 3.9 now opens paths in zip files in text mode by default
            mode = "rb"
        else:
            # but before 3.9 it's not possible to specify binary "b" mode
            mode = "r"

        with zfp.open(mode) as reader:
            _io_copy(reader, writer)