mdbq 4.0.64__tar.gz → 4.0.66__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 (33) hide show
  1. {mdbq-4.0.64 → mdbq-4.0.66}/PKG-INFO +1 -1
  2. mdbq-4.0.66/mdbq/__version__.py +1 -0
  3. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/mysql/s_query.py +95 -1
  4. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq.egg-info/PKG-INFO +1 -1
  5. mdbq-4.0.64/mdbq/__version__.py +0 -1
  6. {mdbq-4.0.64 → mdbq-4.0.66}/README.txt +0 -0
  7. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/__init__.py +0 -0
  8. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/log/__init__.py +0 -0
  9. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/log/mylogger.py +0 -0
  10. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/myconf/__init__.py +0 -0
  11. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/myconf/myconf.py +0 -0
  12. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/mysql/__init__.py +0 -0
  13. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/mysql/deduplicator.py +0 -0
  14. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/mysql/mysql.py +0 -0
  15. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/mysql/unique_.py +0 -0
  16. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/mysql/uploader.py +0 -0
  17. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/other/__init__.py +0 -0
  18. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/other/download_sku_picture.py +0 -0
  19. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/other/error_handler.py +0 -0
  20. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/other/otk.py +0 -0
  21. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/other/pov_city.py +0 -0
  22. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/other/ua_sj.py +0 -0
  23. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/pbix/__init__.py +0 -0
  24. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/pbix/pbix_refresh.py +0 -0
  25. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/pbix/refresh_all.py +0 -0
  26. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/redis/__init__.py +0 -0
  27. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/redis/getredis.py +0 -0
  28. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq/spider/__init__.py +0 -0
  29. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq.egg-info/SOURCES.txt +0 -0
  30. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq.egg-info/dependency_links.txt +0 -0
  31. {mdbq-4.0.64 → mdbq-4.0.66}/mdbq.egg-info/top_level.txt +0 -0
  32. {mdbq-4.0.64 → mdbq-4.0.66}/setup.cfg +0 -0
  33. {mdbq-4.0.64 → mdbq-4.0.66}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mdbq
3
- Version: 4.0.64
3
+ Version: 4.0.66
4
4
  Home-page: https://pypi.org/project/mdbq
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -0,0 +1 @@
1
+ VERSION = '4.0.66'
@@ -779,6 +779,82 @@ class QueryDatas:
779
779
  df[col] = df[col].astype(float)
780
780
  return df
781
781
 
782
+ def _convert_columns_to_lowercase(self, data: Union[pd.DataFrame, List[Dict[str, Any]]],
783
+ lower_col: Optional[List[str]],
784
+ return_format: str) -> Union[pd.DataFrame, List[Dict[str, Any]]]:
785
+ """
786
+ 将指定列的值转换为小写。
787
+
788
+ Args:
789
+ data: 原始数据,可以是DataFrame或列表字典
790
+ lower_col: 需要转换为小写的列名列表
791
+ return_format: 返回数据格式
792
+
793
+ Returns:
794
+ 转换后的数据
795
+ """
796
+ # 参数验证
797
+ if not lower_col:
798
+ return data
799
+
800
+ # 检查data是否为空
801
+ if return_format == 'df':
802
+ if data is None or data.empty:
803
+ return data
804
+ else: # list_dict格式
805
+ if data is None or len(data) == 0:
806
+ return data
807
+
808
+ # 确保 lower_col 是列表类型
809
+ if not isinstance(lower_col, list):
810
+ logger.warning('lower_col 参数类型错误,应为列表', {'传入类型': type(lower_col).__name__})
811
+ return data
812
+
813
+ try:
814
+ if return_format == 'df':
815
+ df = data.copy()
816
+ for col in lower_col:
817
+ if not isinstance(col, str):
818
+ logger.warning('列名必须是字符串类型', {'列名': col, '类型': type(col).__name__})
819
+ continue
820
+
821
+ if col in df.columns:
822
+ # 只对字符串类型的列进行小写转换
823
+ if df[col].dtype == 'object':
824
+ # 更安全的空值处理:保持 None/NaN 不变,只转换非空字符串
825
+ df[col] = df[col].apply(lambda x: str(x).lower() if pd.notna(x) and x is not None else x)
826
+ else:
827
+ logger.debug('列不是字符串类型,跳过小写转换', {'列名': col, '数据类型': df[col].dtype})
828
+ logger.debug('列转换为小写', {'列名': col, '数据类型': df[col].dtype})
829
+ else:
830
+ logger.debug('指定的列不存在,跳过小写转换', {'列名': col, '可用列': list(df.columns)})
831
+ return df
832
+ else: # list_dict格式
833
+ result = []
834
+ for row in data:
835
+ new_row = row.copy()
836
+ for col in lower_col:
837
+ if not isinstance(col, str):
838
+ logger.warning('列名必须是字符串类型', {'列名': col, '类型': type(col).__name__})
839
+ continue
840
+
841
+ if col in new_row and new_row[col] is not None:
842
+ # 确保值是字符串类型再转换为小写
843
+ try:
844
+ new_row[col] = str(new_row[col]).lower()
845
+ except Exception as e:
846
+ logger.debug('值转换为小写失败', {'列名': col, '值': new_row[col], '错误': str(e)})
847
+ # 保持原值不变
848
+ result.append(new_row)
849
+ return result
850
+ except Exception as e:
851
+ logger.warning('小写转换失败', {
852
+ '错误类型': type(e).__name__,
853
+ '错误信息': str(e),
854
+ '指定列': lower_col
855
+ })
856
+ return data
857
+
782
858
  def __enter__(self):
783
859
  """上下文管理器入口"""
784
860
  return self
@@ -831,7 +907,8 @@ class QueryDatas:
831
907
  limit: Optional[int] = None,
832
908
  page_size: Optional[int] = None,
833
909
  date_column: Optional[str] = None,
834
- return_format: Literal['df', 'list_dict'] = 'df'
910
+ return_format: Literal['df', 'list_dict'] = 'df',
911
+ lower_col: Optional[List[str]] = ['店铺名称']
835
912
  ) -> Union[pd.DataFrame, List[Dict[str, Any]]]:
836
913
  """
837
914
  从数据库表获取数据,支持列筛选、日期范围过滤和行数限制。
@@ -855,6 +932,7 @@ class QueryDatas:
855
932
  return_format: 返回数据格式
856
933
  - 'df': 返回pandas DataFrame(默认)
857
934
  - 'list_dict': 返回列表字典格式 [{列1:值, 列2:值, ...}, ...]
935
+ lower_col: 需要转换为小写的列名列表,默认['店铺名称']。如果为None或空列表,则不进行小写转换。
858
936
 
859
937
  Returns:
860
938
  根据return_format参数返回不同格式的数据:
@@ -874,6 +952,18 @@ class QueryDatas:
874
952
  logger.error('无效的return_format值', {'库': db_name, '表': table_name, '指定返回数据格式, 有效值应为: ': ', '.join(valid_formats)})
875
953
  return [] if return_format == 'list_dict' else pd.DataFrame()
876
954
 
955
+ # 验证lower_col参数
956
+ if lower_col is not None:
957
+ if not isinstance(lower_col, list):
958
+ logger.warning('lower_col 参数类型错误,应为列表,将使用默认值', {'传入类型': type(lower_col).__name__})
959
+ lower_col = ['店铺名称']
960
+ elif len(lower_col) > 0:
961
+ # 验证列表中的每个元素都是字符串
962
+ invalid_items = [item for item in lower_col if not isinstance(item, str)]
963
+ if invalid_items:
964
+ logger.warning('lower_col 列表包含非字符串元素,将过滤掉', {'无效元素': invalid_items})
965
+ lower_col = [item for item in lower_col if isinstance(item, str)]
966
+
877
967
  # 验证日期范围
878
968
  start_date, end_date = self._validate_date_range(start_date, end_date, db_name, table_name)
879
969
 
@@ -928,10 +1018,12 @@ class QueryDatas:
928
1018
 
929
1019
  if result:
930
1020
  if return_format == 'list_dict':
1021
+ result = self._convert_columns_to_lowercase(result, lower_col, return_format)
931
1022
  return result
932
1023
  else:
933
1024
  df = pd.DataFrame(result)
934
1025
  df = self._convert_decimal_columns(df)
1026
+ df = self._convert_columns_to_lowercase(df, lower_col, return_format)
935
1027
  return df
936
1028
  return [] if return_format == 'list_dict' else pd.DataFrame()
937
1029
 
@@ -975,11 +1067,13 @@ class QueryDatas:
975
1067
  })
976
1068
 
977
1069
  if return_format == 'list_dict':
1070
+ all_results = self._convert_columns_to_lowercase(all_results, lower_col, return_format)
978
1071
  return all_results
979
1072
  else:
980
1073
  df = pd.DataFrame(all_results)
981
1074
  if not df.empty:
982
1075
  df = self._convert_decimal_columns(df)
1076
+ df = self._convert_columns_to_lowercase(df, lower_col, return_format)
983
1077
  return df
984
1078
 
985
1079
  except Exception as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mdbq
3
- Version: 4.0.64
3
+ Version: 4.0.66
4
4
  Home-page: https://pypi.org/project/mdbq
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -1 +0,0 @@
1
- VERSION = '4.0.64'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes