Commit ebf7e912 authored by Grant, Josh's avatar Grant, Josh
Browse files

remove pandas from Database class

parent cf7ff0a4
Loading
Loading
Loading
Loading
+2 −24
Original line number Diff line number Diff line
@@ -6,12 +6,12 @@ PostgreSQL database. However, the connection paramater may be specified to open
any type of connection through implementation of this abstract class.
"""
import traceback
from abc import ABC, abstractmethod
from abc import ABCMeta, abstractmethod
from common.logz import create_logger
from common.env import check_environment as ce


class Database(ABC):
class Database(ABCMeta):
    """ Provides an abstract class for connecting to a database using
        environmental variables.

@@ -135,28 +135,6 @@ class Database(ABC):
        # If one or both connection and cursor are missing, return False
        return False

    def return_as_pandas(self, query):
        """ return a query as a pandas dataframe """
        self.logger.info(f'Returning {query} as pandas')

        def make_pd_frame(query):
            dfq = self._cursor.execute(query)
            if dfq is None:
                print('unable to fetch data for query: %s' % query)
                return dfq
            df = pd.DataFrame(dfq.fetchall())
            df.columns = dfq.keys()
            return df

        if self.is_open():
            results = make_pd_frame(query)
        else:
            self.logger.warning('DB is not open, consider using "with"')
            self.open()
            results = make_pd_frame(query)
            self.close()
        return results

    def override_connection(self, connection):
        """Override the default connection, useful for using other connections
           than `psycopg2` for downstream development.