From 983d3ec7e2e2e92c782a34c09dd641c9be77e384 Mon Sep 17 00:00:00 2001 From: matteo Date: Mon, 4 Feb 2019 16:04:02 +0100 Subject: [PATCH] fix users_df py-accengage for better memory usage --- .gitignore | 3 ++- accengage/accengage.py | 12 ++++++------ setup.py | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index ecbfcaa..f504c94 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -.venv \ No newline at end of file +.venv +tests \ No newline at end of file diff --git a/accengage/accengage.py b/accengage/accengage.py index ce032b4..0100f94 100644 --- a/accengage/accengage.py +++ b/accengage/accengage.py @@ -96,7 +96,7 @@ def set_headers(self): } return self.headers - def get_output_in_df(self, result, headers): + def get_output_in_list(self, result, headers): """ :param result: response.text from api call @@ -105,14 +105,14 @@ def get_output_in_df(self, result, headers): """ data = BufferIO(result.encode()) if len(result) == 0: - return pd.DataFrame() - df = pd.read_csv(data, sep=";", header=0, encoding='utf-8', error_bad_lines=False) + return [] + data_list = pd.read_csv(data, sep=";", header=0, encoding='utf-8', error_bad_lines=False).to_dict('records') if headers.get('Link'): response = requests.request("GET", headers['Link'].replace('<', '').replace('>; rel="next"', ''), headers=self.set_headers(), params={}) - df = df.append(self.get_output_in_df(response.text, response.headers)) + data_list += self.get_output_in_list(response.text, response.headers) else: pass - return df + return data_list def get_users_df(self, partner_id, last_open=None): - return self.get_output_in_df(*self.get_users(partner_id=partner_id, last_open=last_open)) + return pd.DataFrame(self.get_output_in_list(*self.get_users(partner_id=partner_id, last_open=last_open))) diff --git a/setup.py b/setup.py index bb61919..e4f639b 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ def reqs(*f): setup(name='accengage', - version='0.1.3', + version='0.1.4', url='https://github.com/pualien/py-accengage', license='MIT', author='Matteo Senardi',