#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Apr 24 09:06:13 2020 @author: tanya """ import numpy as np import pandas as pd class TypeConverter: """ Library for methods to manage python types """ def __init__(self): """ """ from cdplib.log import Log self._logger = Log("TypeConverter") def convert_to_ndarray(self, x: (pd.DataFrame, np.ndarray)) -> np.ndarray: ''' Converts an DataFrame to an numpy array. ''' if isinstance(x, np.ndarray): return x elif (isinstance(x, pd.core.frame.DataFrame))\ or (isinstance(x, pd.core.series.Series)): return x.values else: self._logger.log_and_raise_error_stack_info( 'The argument must be a numpy array or a pandas DataFrame')