Functions-d 1.38__tar.gz → 1.40__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.
@@ -7,7 +7,7 @@ import shutil
7
7
  import time
8
8
  import urllib.request
9
9
  import WeComMsg
10
- import xlwings as xw
10
+ # import xlwings as xw
11
11
  import yagmail
12
12
  import HiveClient
13
13
  from PIL import ImageGrab, Image
@@ -20,7 +20,7 @@ from selenium.webdriver.edge.service import Service
20
20
  from selenium.webdriver.edge.options import Options
21
21
  from webdriver_manager.microsoft import EdgeChromiumDriverManager
22
22
  import psutil
23
- import pythoncom
23
+ # import pythoncom
24
24
  from tenacity import retry, stop_after_attempt, wait_fixed
25
25
  import requests
26
26
  import pandas as pd
@@ -676,10 +676,10 @@ class DataProcessingAndMessaging:
676
676
 
677
677
  # -------------------------- 写入Excel数据 --------------------------
678
678
  def writer_excel_data(self, path, filename, send_file, sheet_data, headers):
679
+ import xlwings as xw
679
680
  self.logger.info('开始处理Excel表格')
680
681
  print('开始处理Excel表格')
681
682
  filename = path + filename
682
- send_file = send_file
683
683
  dfs = []
684
684
  sheet_names = []
685
685
  clear_ranges = []
@@ -755,6 +755,8 @@ class DataProcessingAndMessaging:
755
755
 
756
756
  # -------------------------- Excel截图(安全版) --------------------------
757
757
  def screen(self, filename, sheetname, screen_area, img_name):
758
+ import pythoncom
759
+ import xlwings as xw
758
760
  self.logger.info('开始截图')
759
761
  print('开始截图')
760
762
  pythoncom.CoInitialize()
@@ -1912,20 +1914,14 @@ class DataProcessingAndMessaging:
1912
1914
  # -------------------------- Hive数据导出Snappy压缩Parquet文件 --------------------------
1913
1915
  def export_parquet(self, df, file_no_suffix, save_dir=None):
1914
1916
  """
1915
- 将Hive查询返回的DataFrame去除库表前缀列名,自动处理重复字段名,导出snappy压缩parquet文件
1916
- :param df: Hive读取的DataFrame
1917
- :param file_no_suffix: 不带后缀的文件名,方法内部自动拼接 .parquet
1918
- :param save_dir: 存储目录路径;不传则默认使用实例内置self.path
1917
+ 将Hive查询返回的DataFrame,自动去重列名,输出优化参数Snappy Parquet
1919
1918
  """
1920
- # 判定存储目录,为空则使用默认脚本路径self.path
1921
1919
  target_dir = save_dir if save_dir is not None else self.path
1922
- # 拼接完整文件路径
1923
1920
  file_name = f"{file_no_suffix}.parquet"
1924
1921
  save_path = os.path.join(target_dir, file_name)
1925
1922
  self.logger.info(f"开始处理Parquet导出,目标路径:{save_path}")
1926
1923
  print(f"开始处理Parquet导出,目标路径:{save_path}")
1927
1924
  try:
1928
- # 截取列名,去掉库表前缀,重复字段自动加后缀区分
1929
1925
  old_columns = list(df.columns)
1930
1926
  new_cols = []
1931
1927
  name_count = {}
@@ -1939,22 +1935,24 @@ class DataProcessingAndMessaging:
1939
1935
  final_name = short_name
1940
1936
  new_cols.append(final_name)
1941
1937
  df.columns = new_cols
1942
- self.logger.info(f"列名清洗完成,原列名:{old_columns} → 新列名:{list(df.columns)}")
1938
+ self.logger.info(f"列名清洗完成,共{len(df.columns)}个字段")
1943
1939
  print(f"列名清洗完成,共{len(df.columns)}个字段")
1944
1940
 
1945
- # 导出snappy压缩parquet
1941
+ # 增加优化参数,大幅提升PowerBI读取性能
1946
1942
  df.to_parquet(
1947
1943
  save_path,
1948
1944
  engine="pyarrow",
1949
- compression="snappy"
1945
+ compression="snappy",
1946
+ row_group_size=100000,
1947
+ use_dictionary=True,
1948
+ data_page_size=1048576
1950
1949
  )
1951
- # 获取文件大小日志
1952
1950
  file_size_kb = round(os.path.getsize(save_path) / 1024, 2)
1953
- success_msg = f"Parquet文件导出完成,文件大小:{file_size_kb} KB,数据行数:{len(df)}"
1951
+ success_msg = f"Parquet导出完成,文件大小:{file_size_kb} KB,数据行数:{len(df)}"
1954
1952
  self.logger.info(success_msg)
1955
1953
  print(success_msg)
1956
1954
  except Exception as e:
1957
- err_msg = f"导出Snappy Parquet文件失败,保存路径:{save_path},报错信息:{str(e)}"
1955
+ err_msg = f"导出Parquet失败,路径:{save_path},报错:{str(e)}"
1958
1956
  self.logger.error(err_msg, exc_info=True)
1959
1957
  print(err_msg)
1960
1958
  raise
@@ -1989,7 +1987,7 @@ class DataProcessingAndMessaging:
1989
1987
  final_name = short_name
1990
1988
  new_cols.append(final_name)
1991
1989
  df.columns = new_cols
1992
- self.logger.info(f"列名清洗完成,原列名:{old_columns} → 新列名:{list(df.columns)}")
1990
+ self.logger.info(f"列名清洗完成,共{len(df.columns)}个字段")
1993
1991
  print(f"列名清洗完成,共{len(df.columns)}个字段")
1994
1992
 
1995
1993
  # 导出csv,utf-8-sig解决中文乱码,不输出索引
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Functions_d
3
- Version: 1.38
3
+ Version: 1.40
4
4
  Summary: 包含数据处理、Hive交互、企业微信消息发送、Excel操作等功能的工具类库
5
5
  Author: DongYang
6
6
  Author-email: 649898871@qq.com
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Functions_d
3
- Version: 1.38
3
+ Version: 1.40
4
4
  Summary: 包含数据处理、Hive交互、企业微信消息发送、Excel操作等功能的工具类库
5
5
  Author: DongYang
6
6
  Author-email: 649898871@qq.com
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = Functions_d
3
- version = 1.38
3
+ version = 1.40
4
4
  author = DongYang
5
5
  author_email = 649898871@qq.com
6
6
  description = 包含数据处理、Hive交互、企业微信消息发送、Excel操作等功能的工具类库
File without changes
File without changes
File without changes