funcguard 0.2.47__tar.gz → 0.2.49__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 (35) hide show
  1. {funcguard-0.2.47 → funcguard-0.2.49}/PKG-INFO +1 -1
  2. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/statistics/mask_utils.py +24 -4
  3. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard.egg-info/PKG-INFO +1 -1
  4. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard.egg-info/SOURCES.txt +2 -1
  5. {funcguard-0.2.47 → funcguard-0.2.49}/setup.py +1 -1
  6. funcguard-0.2.49/tests/test_pd_filter_empty.py +34 -0
  7. {funcguard-0.2.47 → funcguard-0.2.49}/LICENSE +0 -0
  8. {funcguard-0.2.47 → funcguard-0.2.49}/README.md +0 -0
  9. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/__init__.py +0 -0
  10. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/calculate.py +0 -0
  11. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/core.py +0 -0
  12. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/data_models/__init__.py +0 -0
  13. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/data_models/request_models.py +0 -0
  14. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/ip_utils.py +0 -0
  15. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/log_utils.py +0 -0
  16. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/__init__.py +0 -0
  17. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/convert_utils.py +0 -0
  18. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/date_utils.py +0 -0
  19. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/fill_round.py +0 -0
  20. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/filter.py +0 -0
  21. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/json_utils/__init__.py +0 -0
  22. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/json_utils/json_parser.py +0 -0
  23. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/statistics/__init__.py +0 -0
  24. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/statistics/agg_utils.py +0 -0
  25. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/statistics/count_utils.py +0 -0
  26. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/pd_utils/statistics/df_statistics.py +0 -0
  27. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/printer.py +0 -0
  28. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/time_utils.py +0 -0
  29. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard/tools.py +0 -0
  30. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard.egg-info/dependency_links.txt +0 -0
  31. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard.egg-info/not-zip-safe +0 -0
  32. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard.egg-info/requires.txt +0 -0
  33. {funcguard-0.2.47 → funcguard-0.2.49}/funcguard.egg-info/top_level.txt +0 -0
  34. {funcguard-0.2.47 → funcguard-0.2.49}/setup.cfg +0 -0
  35. {funcguard-0.2.47 → funcguard-0.2.49}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: funcguard
3
- Version: 0.2.47
3
+ Version: 0.2.49
4
4
  Summary: FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。
5
5
  Home-page: https://github.com/tinycen/funcguard
6
6
  Author: tinycen
@@ -1,22 +1,42 @@
1
+ import numpy as np
1
2
  import pandas as pd
2
3
  from typing import List, Tuple, Optional
3
4
 
4
5
 
6
+
5
7
  def _is_empty(x):
6
8
  """检查值是否为空(NaN/None、空字符串、空列表、空元组、空字典、空集合)"""
7
- if pd.isna(x):
8
- return True
9
+ # 处理 numpy/pandas 数组类型(0维数组也会被isinstance识别)
10
+ if isinstance(x, (np.ndarray, pd.Series)):
11
+ return x.size == 0
12
+ # 原生容器优先按长度判断,避免 pd.isna([]) 返回空数组引发歧义
9
13
  if isinstance(x, (str, list, tuple, dict, set)):
10
14
  return len(x) == 0
15
+ # 使用 try-except 避免 pd.isna() 在某些类型上的歧义
16
+ try:
17
+ if pd.isna(x):
18
+ return True
19
+ except ValueError:
20
+ # pd.isna() 返回数组或产生歧义时,说明不是空值
21
+ pass
11
22
  return False
12
23
 
13
24
 
14
25
  def _is_not_empty(x):
15
26
  """检查值是否非空(与_is_empty相反)"""
16
- if pd.isna(x):
17
- return False
27
+ # 处理 numpy/pandas 数组类型
28
+ if isinstance(x, (np.ndarray, pd.Series)):
29
+ return x.size > 0
30
+ # 原生容器优先按长度判断,避免 pd.isna([]) 返回空数组引发歧义
18
31
  if isinstance(x, (str, list, tuple, dict, set)):
19
32
  return len(x) > 0
33
+ # 使用 try-except 避免 pd.isna() 在某些类型上的歧义
34
+ try:
35
+ if pd.isna(x):
36
+ return False
37
+ except ValueError:
38
+ # pd.isna() 返回数组或产生歧义时,说明有值
39
+ return True
20
40
  return True
21
41
 
22
42
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: funcguard
3
- Version: 0.2.47
3
+ Version: 0.2.49
4
4
  Summary: FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。
5
5
  Home-page: https://github.com/tinycen/funcguard
6
6
  Author: tinycen
@@ -29,4 +29,5 @@ funcguard/pd_utils/statistics/agg_utils.py
29
29
  funcguard/pd_utils/statistics/count_utils.py
30
30
  funcguard/pd_utils/statistics/df_statistics.py
31
31
  funcguard/pd_utils/statistics/mask_utils.py
32
- tests/__init__.py
32
+ tests/__init__.py
33
+ tests/test_pd_filter_empty.py
@@ -9,7 +9,7 @@ except FileNotFoundError:
9
9
 
10
10
  setup(
11
11
  name='funcguard',
12
- version='0.2.47',
12
+ version='0.2.49',
13
13
  packages=find_packages(),
14
14
  install_requires=[
15
15
  'requests',
@@ -0,0 +1,34 @@
1
+ import math
2
+
3
+ import pandas as pd
4
+
5
+ from funcguard.pd_utils.filter import pd_filter
6
+ from funcguard.pd_utils.statistics.mask_utils import _is_empty, _is_not_empty
7
+
8
+
9
+ def test_empty_helpers_handle_empty_list_correctly():
10
+ assert _is_empty([]) is True
11
+ assert _is_not_empty([]) is False
12
+ assert _is_empty([1]) is False
13
+ assert _is_not_empty([1]) is True
14
+
15
+
16
+ def test_pd_filter_not_empty_excludes_real_empty_containers_and_nan():
17
+ df = pd.DataFrame(
18
+ {
19
+ "segments": [
20
+ [],
21
+ [1, 2],
22
+ None,
23
+ math.nan,
24
+ "",
25
+ "[]",
26
+ {},
27
+ {"a": 1},
28
+ ]
29
+ }
30
+ )
31
+
32
+ filtered = pd_filter(df, ("segments", "not empty"))
33
+
34
+ assert filtered["segments"].tolist() == [[1, 2], "[]", {"a": 1}]
File without changes
File without changes
File without changes
File without changes
File without changes