Fix streaming
Browse filesgzip.open only works for local files, not with URLs
To open remote files in streaming mode, we extend `open` to support URLs.
This should fix https://github.com/huggingface/datasets/issues/5060
- pubchem_selfies.py +11 -12
pubchem_selfies.py
CHANGED
|
@@ -472,15 +472,14 @@ class PubchemSelfies(datasets.GeneratorBasedBuilder):
|
|
| 472 |
def _generate_examples(self, subdirs, split):
|
| 473 |
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
| 474 |
for filepath in subdirs:
|
| 475 |
-
with gzip.open(filepath,
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
}
|
|
|
|
| 472 |
def _generate_examples(self, subdirs, split):
|
| 473 |
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
| 474 |
for filepath in subdirs:
|
| 475 |
+
with gzip.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
|
| 476 |
+
for key, row in enumerate(rows):
|
| 477 |
+
data = json.loads(row)
|
| 478 |
+
properties = data["molecules"][0]["properties"]
|
| 479 |
+
yield key, {
|
| 480 |
+
"PUBCHEM_COMPOUND_CID": properties["PUBCHEM_COMPOUND_CID"],
|
| 481 |
+
"PUBCHEM_OPENEYE_CAN_SMILES": properties[
|
| 482 |
+
"PUBCHEM_OPENEYE_CAN_SMILES"
|
| 483 |
+
],
|
| 484 |
+
"CAN_SELFIES": properties["CAN_SELFIES"],
|
| 485 |
+
}
|
|
|