berryworld 1.0.0.188349__py3-none-any.whl → 1.0.0.189012__py3-none-any.whl

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.
@@ -29,7 +29,7 @@ class SnowflakeConn:
29
29
  except KeyError:
30
30
  raise KeyError('Please provide a valid db_name and server_type')
31
31
 
32
- self.db = kwargs['db_name']
32
+ self.db = server_creds['db_name']
33
33
  self.user = server_creds['user_name']
34
34
  self.pw = server_creds['password']
35
35
  self.account = server_creds['account']
berryworld/sql_conn.py CHANGED
@@ -243,7 +243,8 @@ class SQLConn:
243
243
  self.close_connection()
244
244
 
245
245
  def insert(self, data, schema, table, truncate=False, delete=False, identity=False, chunk=1000, print_sql=False,
246
- commit_all_together=False, output=None, bools2bits=True, nullable=False, commit_as_transaction=True):
246
+ commit_all_together=False, output=None, bools2bits=True, nullable=False, commit_as_transaction=True,
247
+ infer_datetime_format=None):
247
248
  """ Insert data in a table in SQL truncating the table if needed
248
249
  -----------------------------
249
250
  df = pd.DataFrame({'col1': ['a', 'b'], 'col2': [1, 2]})
@@ -265,6 +266,8 @@ class SQLConn:
265
266
  :return: A DataFrame with the output columns requested if output is not None, else None
266
267
  :param nullable: Used within bools2bits function to indicate which boolean column values to convert
267
268
  :param commit_as_transaction: Indicate whether the connection will be done using the autocommit option or not
269
+ :param infer_datetime_format: Indicate whether the datetime columns should be converted to string and if so,
270
+ then the format to be used
268
271
  """
269
272
  if output is None:
270
273
  output = []
@@ -278,8 +281,9 @@ class SQLConn:
278
281
  # Mapping the date datatype columns for SQL
279
282
  data = self.date_mapping_data_types(data)
280
283
 
281
- # # Infer integer datatype columns for SQL
282
- # data = self.int_mapping_data_types(data)
284
+ # Infer datetime format if provided
285
+ if infer_datetime_format is not None:
286
+ data = self.infer_datetime(data, infer_datetime_format)
283
287
 
284
288
  # Mapping the boolean columns to bit
285
289
  if bools2bits:
@@ -376,9 +380,6 @@ class SQLConn:
376
380
  # Mapping the date datatype columns for SQL
377
381
  data = self.date_mapping_data_types(data)
378
382
 
379
- # # Infer integer datatype columns for SQL
380
- # data = self.int_mapping_data_types(data)
381
-
382
383
  # Mapping the boolean columns to bit
383
384
  if bools2bits:
384
385
  data = self.boolean_mapping_data_types(data, nullable)
@@ -490,9 +491,6 @@ class SQLConn:
490
491
  # Mapping date type for SQL
491
492
  data = self.date_mapping_data_types(data)
492
493
 
493
- # # Infer integer datatype columns for SQL
494
- # data = self.int_mapping_data_types(data)
495
-
496
494
  # create connection
497
495
  self.open_write_connection(commit_as_transaction)
498
496
 
@@ -632,9 +630,6 @@ class SQLConn:
632
630
  data = data[on_list + update_list]
633
631
  data = self.date_mapping_data_types(data)
634
632
 
635
- # # Infer integer datatype columns for SQL
636
- # data = self.int_mapping_data_types(data)
637
-
638
633
  # create connection
639
634
  self.open_write_connection(commit_as_transaction)
640
635
 
@@ -934,30 +929,6 @@ class SQLConn:
934
929
 
935
930
  return data
936
931
 
937
- @staticmethod
938
- def int_mapping_data_types(data):
939
- """
940
- Map integer variables so they can be inserted as integer to SQL
941
- :param data: DataFrame containing the variables to map
942
- :return: The mapped DataFrame
943
- """
944
- thres_ = 0.9
945
- for col in data.columns:
946
- try:
947
- if (((~(data[col].isnull())) & (data[col].str.contains('.0', regex=False))).sum() / (
948
- ~data[col].isnull()).sum() > thres_) & (~data[col].str.contains('{', regex=False)):
949
- # Avoid converting datetime values
950
- try:
951
- pd.to_datetime(data[col])
952
- except Exception as e:
953
- print(e)
954
- data[col] = data[col].str.replace('.0', '')
955
- except Exception as e:
956
- print(e)
957
- continue
958
-
959
- return data
960
-
961
932
  @staticmethod
962
933
  def boolean_mapping_data_types(data, nullable=False):
963
934
  """
@@ -1008,3 +979,14 @@ class SQLConn:
1008
979
  """
1009
980
  string = re.sub("'\)(?!(,[ ]+\())(?=([^$]))", "", string)
1010
981
  return re.sub("Decimal\('", "", string)
982
+
983
+ @staticmethod
984
+ def infer_datetime(data, infer_datetime_format):
985
+ """ Method to infer datetime columns and format them as string
986
+ :param data: DataFrame to parse
987
+ :param infer_datetime_format: format to be used for the datetime columns
988
+ """
989
+ for col in data.select_dtypes(include=['datetime64']).columns:
990
+ data[col] = pd.to_datetime(data[col]).dt.strftime(infer_datetime_format)
991
+
992
+ return data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: berryworld
3
- Version: 1.0.0.188349
3
+ Version: 1.0.0.189012
4
4
  Summary: Handy classes to improve ETL processes
5
5
  Home-page: https://www.berryworld.com
6
6
  Author: BerryWorld ltd
@@ -17,20 +17,20 @@ berryworld/persistent_storage.py,sha256=KQA57ez8eVTUCtudYkHPg_S5lcOEa_E7xXcaN1DY
17
17
  berryworld/pickle_management.py,sha256=5o6UuXBpTj23Jgpz6sj9V-vdcdWBK1xMEckWxT-Whj4,2436
18
18
  berryworld/power_automate.py,sha256=Y11GoeDEwd3Y2RdvtPPhBSFK65APEceAQKtNo4gVLK4,26464
19
19
  berryworld/sharepoint_con.py,sha256=TuH-Vxk1VxjTi7x80KFssf_J8YPLRXpV27RBaFZi37U,22254
20
- berryworld/snowflake_conn.py,sha256=52ugfkyVCbR_Xr8YiZtNwPrwe93_1uE9uRy_VNPT6Gs,2428
21
- berryworld/sql_conn.py,sha256=3_uPrn3rJjVr7-9wcXkh0CSitFD2ncQGGZjttFl6ELM,47803
20
+ berryworld/snowflake_conn.py,sha256=go5ZJjnhz5SkG83B0G0XZSwKgU6tg7AFTBso59oRG5M,2434
21
+ berryworld/sql_conn.py,sha256=r2rAVRc3Mes0m6_62J4uFg5GLBNMr7Vkme9Ip6jT3aA,47283
22
22
  berryworld/teams_logging.py,sha256=8NwXyWr4fLj7W6GzAm2nRQCGFDxibQpAHDHHD24FrP8,6997
23
23
  berryworld/transportation_solver.py,sha256=tNc1JJk71azIBccdWVHbqcvXWhalOdKffv6HmBD6tG0,5014
24
24
  berryworld/verify_keys.py,sha256=X4Nuz3o0XbRDYofbJGvxIDeN5gfWj19PN7lhO6T3hR8,4356
25
25
  berryworld/vivantio.py,sha256=QfZo0UKqkzVRg_LyiwivNd3aEup4TH57x4KxLZkCJwc,10627
26
26
  berryworld/vivantio_logging.py,sha256=ciy7gA4u3FrgUIpEBnMgocbNPp6jcu9TPoy-kLcrTZU,5736
27
27
  berryworld/xml_parser.py,sha256=HWD71NaTN3DaIOGT6Wzxs4CEsroFhGQwe9iPLIL80Co,957
28
- berryworld-1.0.0.188349.dist-info/licenses/LICENSE,sha256=vtkVCJM6E2af2gnsi2XxKPr4WY-uIbvzVLXieFND0UU,1074
28
+ berryworld-1.0.0.189012.dist-info/licenses/LICENSE,sha256=vtkVCJM6E2af2gnsi2XxKPr4WY-uIbvzVLXieFND0UU,1074
29
29
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
30
  tests/test_allocation_config.py,sha256=e12l6fE9U57eSPS35g6ekJ_hol7-RHg89JV60_m1BlE,4633
31
31
  tests/test_handy_mix_config.py,sha256=Un56mz9KJmdn4K4OwzHAHLSRzDU1Xv2nFrONNuzOG04,2594
32
32
  tests/test_xml_parser.py,sha256=3QTlhFEd6KbK6nRFKZnc35tad6wqukTbe4QrFi8mr_8,859
33
- berryworld-1.0.0.188349.dist-info/METADATA,sha256=IQNILK3na6R8NKy5LsS7k4mRTciBjh9mJjsdlVI-Sv0,1362
34
- berryworld-1.0.0.188349.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
35
- berryworld-1.0.0.188349.dist-info/top_level.txt,sha256=GIZ5qy-P5oxfEH755vA1IMFeTVdX3-40JxMe6nOe5I8,17
36
- berryworld-1.0.0.188349.dist-info/RECORD,,
33
+ berryworld-1.0.0.189012.dist-info/METADATA,sha256=G_C7noVeA6eQTLZN_aevjCibBaGJ0dj3dk6mawRqrlY,1362
34
+ berryworld-1.0.0.189012.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
35
+ berryworld-1.0.0.189012.dist-info/top_level.txt,sha256=GIZ5qy-P5oxfEH755vA1IMFeTVdX3-40JxMe6nOe5I8,17
36
+ berryworld-1.0.0.189012.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (79.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5