# These pickle handlers rely on Numpy and Pandas, so it only makes sense to register # them if Numpy or Pandas are installed. try: import jsonpickle.ext.numpy as jsonpickle_numpy # Make sure Numpy and Pandas objects can be correctly encoded. # https://github.com/jsonpickle/jsonpickle#numpy-support jsonpickle_numpy.register_handlers() except ImportError: pass try: import jsonpickle.ext.pandas as jsonpickle_pandas jsonpickle_pandas.register_handlers() except ImportError: pass _INSTALLATION_PATHS = list(sysconfig.get_paths().values()) _PYTHON_EXECUTABLE_PATH = sys.executable jsonpickle.set_preferred_backend("ujson") # To not let it show warnings @cheap_repr.register_repr(argparse.Namespace) def repr_for_namespace(_, __): return "argparse.Namespace"
# under the terms of the GNU Lesser General Public License as published by # # the Free Software Foundation, either version 3 of the License, or (at your # # option) any later version. # # # # This program is distributed in the hope that it will be useful, but # # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # # or FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License for more details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with this program. # # If not, see <https://www.gnu.org/licenses/>. # # ############################################################################## import pickle from metrics.wallet.analysis import Analysis, BasicAnalysis, DecisionAnalysis, OptiAnalysis, \ find_best_cpu_time_input, export_data_frame from autograph.core.enumstyle import * import pandas as pd import jsonpickle.ext.pandas as jsonpickle_pd jsonpickle_pd.register_handlers() def import_analysis_from_file(filename) -> DecisionAnalysis: with open(filename, 'rb') as file: if filename.split('.')[-1] == 'csv': return DecisionAnalysis(data_frame=pd.read_csv(file)) return DecisionAnalysis(data_frame=pickle.load(file))