Skip to content

Commit

Permalink
use handler instead of path
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Jan 31, 2024
1 parent 8654001 commit c624748
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions easyDataverse/dataverse.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import asyncio
from copy import deepcopy
import json
import os
from typing import Callable, Dict, List, Optional, Tuple
from typing import Callable, Dict, List, Optional, Tuple, IO
from urllib import parse

import requests
Expand Down Expand Up @@ -411,24 +410,24 @@ def _process_compound(self, compound, tree):
return self._extract_data(compound, tree)

# ! Importers
def dataset_from_json(self, path: str) -> Dataset:
def dataset_from_json(self, handler: IO) -> Dataset:
"""
Creates a dataset object from a JSON file.
Args:
path (str): The path to the JSON file.
handler (IO): The file handler for the JSON file.
Returns:
Dataset: The created dataset object.
Raises:
AssertionError: If the Dataverse installation is not connected or if the file does not exist.
"""

assert self._connected, "Please connect to a Dataverse installation first."
assert os.path.exists(path), "File does not exist."

dataset = self.create_dataset()
data = json.load(open(path))
data = json.load(handler)

# Map metadatablocks to dataset
self._map_blocks_to_dataset(dataset, data)
Expand All @@ -445,6 +444,7 @@ def dataset_from_json_string(self, json_string: str) -> Dataset:
Returns:
Dataset: The dataset object created from the JSON string.
"""

assert self._connected, "Please connect to a Dataverse installation first."

dataset = self.create_dataset()
Expand Down

0 comments on commit c624748

Please sign in to comment.