wcp-library 1.2.4__tar.gz → 1.2.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {wcp_library-1.2.4 → wcp_library-1.2.6}/PKG-INFO +1 -1
  2. {wcp_library-1.2.4 → wcp_library-1.2.6}/pyproject.toml +1 -1
  3. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/async_sql/oracle.py +21 -8
  4. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/async_sql/postgres.py +21 -0
  5. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/credentials/postgres.py +1 -1
  6. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/sql/oracle.py +21 -8
  7. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/sql/postgres.py +23 -9
  8. {wcp_library-1.2.4 → wcp_library-1.2.6}/README.md +0 -0
  9. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/__init__.py +0 -0
  10. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/async_credentials/__init__.py +0 -0
  11. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/async_credentials/api.py +0 -0
  12. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/async_credentials/oracle.py +0 -0
  13. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/async_credentials/postgres.py +0 -0
  14. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/async_sql/__init__.py +0 -0
  15. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/credentials/__init__.py +0 -0
  16. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/credentials/ftp.py +0 -0
  17. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/credentials/oracle.py +0 -0
  18. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/emailing.py +0 -0
  19. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/ftp/__init__.py +0 -0
  20. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/ftp/ftp.py +0 -0
  21. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/ftp/sftp.py +0 -0
  22. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/informatica.py +0 -0
  23. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/logging.py +0 -0
  24. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/selenium_helper.py +0 -0
  25. {wcp_library-1.2.4 → wcp_library-1.2.6}/wcp_library/sql/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wcp-library
3
- Version: 1.2.4
3
+ Version: 1.2.6
4
4
  Summary: Common utilites for internal development at WCP
5
5
  Home-page: https://github.com/Whitecap-DNA/WCP-Library
6
6
  Author: Mitch-Petersen
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "wcp-library"
3
- version = "1.2.4"
3
+ version = "1.2.6"
4
4
  description = "Common utilites for internal development at WCP"
5
5
  authors = ["Mitch-Petersen <mitch.petersen@wcap.ca>"]
6
6
  readme = "README.md"
@@ -187,6 +187,27 @@ class AsyncOracleConnection(object):
187
187
  rows = await cursor.fetchall()
188
188
  return rows
189
189
 
190
+ @retry
191
+ async def remove_matching_data(self, dfObj: pd.DataFrame, outputTableName, match_cols: list) -> None:
192
+ """
193
+ Remove matching data from the warehouse
194
+
195
+ :param dfObj: DataFrame
196
+ :param outputTableName: output table name
197
+ :param match_cols: list of columns
198
+ :return: None
199
+ """
200
+
201
+ match_cols = ', '.join(match_cols)
202
+ param_list = []
203
+ for column in match_cols:
204
+ param_list.append(f"{column} = :{column}")
205
+ params = ' AND '.join(param_list)
206
+
207
+ main_dict = dfObj.to_dict('records')
208
+ query = f"""DELETE FROM {outputTableName} WHERE {params}"""
209
+ await self.execute_many(query, main_dict)
210
+
190
211
  @retry
191
212
  async def export_DF_to_warehouse(self, dfObj: pd.DataFrame, outputTableName: str, columns: list, remove_nan=False) -> None:
192
213
  """
@@ -209,14 +230,6 @@ class AsyncOracleConnection(object):
209
230
  dfObj = dfObj.replace({np.nan: None})
210
231
  main_dict = dfObj.to_dict('records')
211
232
 
212
- # if remove_nan:
213
- # for val, item in enumerate(main_dict):
214
- # for sub_item, value in item.items():
215
- # if pd.isna(value):
216
- # main_dict[val][sub_item] = None
217
- # else:
218
- # main_dict[val][sub_item] = value
219
-
220
233
  query = """INSERT INTO {} ({}) VALUES ({})""".format(outputTableName, col, bind)
221
234
  await self.execute_many(query, main_dict)
222
235
 
@@ -170,6 +170,27 @@ class AsyncPostgresConnection(object):
170
170
  rows = await cursor.fetchall()
171
171
  return rows
172
172
 
173
+ @retry
174
+ async def remove_matching_data(self, dfObj: pd.DataFrame, outputTableName, match_cols: list) -> None:
175
+ """
176
+ Remove matching data from the warehouse
177
+
178
+ :param dfObj: DataFrame
179
+ :param outputTableName: output table name
180
+ :param match_cols: list of columns
181
+ :return: None
182
+ """
183
+
184
+ match_cols = ', '.join(match_cols)
185
+ param_list = []
186
+ for column in match_cols:
187
+ param_list.append(f"{column} = %({column})s")
188
+ params = ' AND '.join(param_list)
189
+
190
+ main_dict = dfObj.to_dict('records')
191
+ query = """DELETE FROM {} WHERE {}""".format(outputTableName, params)
192
+ await self.execute_many(query, main_dict)
193
+
173
194
  @retry
174
195
  async def export_DF_to_warehouse(self, dfObj: pd.DataFrame, outputTableName: str, columns: list, remove_nan=False) -> None:
175
196
  """
@@ -13,7 +13,7 @@ class PostgresCredentialManager:
13
13
  self.password_url = URL("https://vault.wcap.ca/api/passwords/")
14
14
  self.api_key = passwordState_api_key
15
15
  self.headers = {"APIKey": self.api_key, 'Reason': 'Python Script Access'}
16
- self._password_list_id = 207
16
+ self._password_list_id = 210
17
17
 
18
18
  def _get_credentials(self) -> dict:
19
19
  """
@@ -191,6 +191,27 @@ class OracleConnection(object):
191
191
  self._session_pool.release(connection)
192
192
  return rows
193
193
 
194
+ @retry
195
+ def remove_matching_data(self, dfObj: pd.DataFrame, outputTableName, match_cols: list) -> None:
196
+ """
197
+ Remove matching data from the warehouse
198
+
199
+ :param dfObj: DataFrame
200
+ :param outputTableName: output table name
201
+ :param match_cols: list of columns
202
+ :return: None
203
+ """
204
+
205
+ match_cols = ', '.join(match_cols)
206
+ param_list = []
207
+ for column in match_cols:
208
+ param_list.append(f"{column} = :{column}")
209
+ params = ' AND '.join(param_list)
210
+
211
+ main_dict = dfObj.to_dict('records')
212
+ query = f"""DELETE FROM {outputTableName} WHERE {params}"""
213
+ self.execute_many(query, main_dict)
214
+
194
215
  @retry
195
216
  def export_DF_to_warehouse(self, dfObj: pd.DataFrame, outputTableName: str, columns: list, remove_nan=False) -> None:
196
217
  """
@@ -213,14 +234,6 @@ class OracleConnection(object):
213
234
  dfObj = dfObj.replace({np.nan: None})
214
235
  main_dict = dfObj.to_dict('records')
215
236
 
216
- # if remove_nan:
217
- # for val, item in enumerate(main_dict):
218
- # for sub_item, value in item.items():
219
- # if pd.isna(value):
220
- # main_dict[val][sub_item] = None
221
- # else:
222
- # main_dict[val][sub_item] = value
223
-
224
237
  query = """INSERT INTO {} ({}) VALUES ({})""".format(outputTableName, col, bind)
225
238
  self.execute_many(query, main_dict)
226
239
 
@@ -149,7 +149,8 @@ class PostgresConnection(object):
149
149
  """
150
150
 
151
151
  with self._session_pool.connection() as connection:
152
- connection.executemany(query, dictionary)
152
+ cursor = connection.cursor()
153
+ cursor.executemany(query, dictionary)
153
154
 
154
155
  @retry
155
156
  def fetch_data(self, query: SQL | str, packed_data=None):
@@ -170,6 +171,27 @@ class PostgresConnection(object):
170
171
  rows = cursor.fetchall()
171
172
  return rows
172
173
 
174
+ @retry
175
+ def remove_matching_data(self, dfObj: pd.DataFrame, outputTableName, match_cols: list) -> None:
176
+ """
177
+ Remove matching data from the warehouse
178
+
179
+ :param dfObj: DataFrame
180
+ :param outputTableName: output table name
181
+ :param match_cols: list of columns
182
+ :return: None
183
+ """
184
+
185
+ match_cols = ', '.join(match_cols)
186
+ param_list = []
187
+ for column in match_cols:
188
+ param_list.append(f"{column} = %({column})s")
189
+ params = ' AND '.join(param_list)
190
+
191
+ main_dict = dfObj.to_dict('records')
192
+ query = """DELETE FROM {} WHERE {}""".format(outputTableName, params)
193
+ self.execute_many(query, main_dict)
194
+
173
195
  @retry
174
196
  def export_DF_to_warehouse(self, dfObj: pd.DataFrame, outputTableName: str, columns: list, remove_nan=False) -> None:
175
197
  """
@@ -192,14 +214,6 @@ class PostgresConnection(object):
192
214
  dfObj = dfObj.replace({np.nan: None})
193
215
  main_dict = dfObj.to_dict('records')
194
216
 
195
- # if remove_nan:
196
- # for val, item in enumerate(main_dict):
197
- # for sub_item, value in item.items():
198
- # if pd.isna(value):
199
- # main_dict[val][sub_item] = None
200
- # else:
201
- # main_dict[val][sub_item] = value
202
-
203
217
  query = """INSERT INTO {} ({}) VALUES ({})""".format(outputTableName, col, params)
204
218
  self.execute_many(query, main_dict)
205
219
 
File without changes