From 0bfca02a6188c9c62e66081671465c6027fae952 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Wed, 16 Feb 2022 16:14:35 +0100 Subject: [PATCH] Moved read_json_file() function outside of class JsonImporter --- src/pyctbn/legacy/utility/json_importer.py | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/pyctbn/legacy/utility/json_importer.py b/src/pyctbn/legacy/utility/json_importer.py index ccf704a..0641c6f 100755 --- a/src/pyctbn/legacy/utility/json_importer.py +++ b/src/pyctbn/legacy/utility/json_importer.py @@ -10,6 +10,19 @@ import pandas as pd from .abstract_importer import AbstractImporter +def read_json_file(file_path) -> typing.List: + """Reads the JSON file in the path self.filePath. + + :return: The contents of the json file + :rtype: List + """ + with open(file_path) as f: + data = json.load(f) + + if (isinstance(data,list)): + return data + else: + return [data] class JsonImporter(AbstractImporter): """Implements the abstracts methods of AbstractImporter and adds all the necessary methods to process and prepare @@ -52,7 +65,7 @@ class JsonImporter(AbstractImporter): self._df_samples_list = None self._array_indx = None super(JsonImporter, self).__init__(file_path) - self._raw_data = self.read_json_file() + self._raw_data = read_json_file(file_path) def import_data(self, indx: int = 0) -> None: """Implements the abstract method of :class:`AbstractImporter`. @@ -101,21 +114,6 @@ class JsonImporter(AbstractImporter): """ return self.one_level_normalizing(raw_data, self._array_indx, self._variables_label) - def read_json_file(self) -> typing.List: - """Reads the JSON file in the path self.filePath. - - :return: The contents of the json file - :rtype: List - """ - with open(self._file_path) as f: - data = json.load(f) - - if (isinstance(data,list)): - return data - else: - return [data] - - def one_level_normalizing(self, raw_data: typing.List, indx: int, key: str) -> pd.DataFrame: """Extracts the one-level nested data in the list ``raw_data`` at the index ``indx`` at the key ``key``.