funcguard 0.2.48__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.
- {funcguard-0.2.48 → funcguard-0.2.49}/PKG-INFO +1 -1
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/statistics/mask_utils.py +6 -4
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard.egg-info/PKG-INFO +1 -1
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard.egg-info/SOURCES.txt +2 -1
- {funcguard-0.2.48 → funcguard-0.2.49}/setup.py +1 -1
- funcguard-0.2.49/tests/test_pd_filter_empty.py +34 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/LICENSE +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/README.md +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/__init__.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/calculate.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/core.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/data_models/__init__.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/data_models/request_models.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/ip_utils.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/log_utils.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/__init__.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/convert_utils.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/date_utils.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/fill_round.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/filter.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/json_utils/__init__.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/json_utils/json_parser.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/statistics/__init__.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/statistics/agg_utils.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/statistics/count_utils.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/pd_utils/statistics/df_statistics.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/printer.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/time_utils.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard/tools.py +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard.egg-info/dependency_links.txt +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard.egg-info/not-zip-safe +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard.egg-info/requires.txt +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/funcguard.egg-info/top_level.txt +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/setup.cfg +0 -0
- {funcguard-0.2.48 → funcguard-0.2.49}/tests/__init__.py +0 -0
|
@@ -9,6 +9,9 @@ def _is_empty(x):
|
|
|
9
9
|
# 处理 numpy/pandas 数组类型(0维数组也会被isinstance识别)
|
|
10
10
|
if isinstance(x, (np.ndarray, pd.Series)):
|
|
11
11
|
return x.size == 0
|
|
12
|
+
# 原生容器优先按长度判断,避免 pd.isna([]) 返回空数组引发歧义
|
|
13
|
+
if isinstance(x, (str, list, tuple, dict, set)):
|
|
14
|
+
return len(x) == 0
|
|
12
15
|
# 使用 try-except 避免 pd.isna() 在某些类型上的歧义
|
|
13
16
|
try:
|
|
14
17
|
if pd.isna(x):
|
|
@@ -16,8 +19,6 @@ def _is_empty(x):
|
|
|
16
19
|
except ValueError:
|
|
17
20
|
# pd.isna() 返回数组或产生歧义时,说明不是空值
|
|
18
21
|
pass
|
|
19
|
-
if isinstance(x, (str, list, tuple, dict, set)):
|
|
20
|
-
return len(x) == 0
|
|
21
22
|
return False
|
|
22
23
|
|
|
23
24
|
|
|
@@ -26,6 +27,9 @@ def _is_not_empty(x):
|
|
|
26
27
|
# 处理 numpy/pandas 数组类型
|
|
27
28
|
if isinstance(x, (np.ndarray, pd.Series)):
|
|
28
29
|
return x.size > 0
|
|
30
|
+
# 原生容器优先按长度判断,避免 pd.isna([]) 返回空数组引发歧义
|
|
31
|
+
if isinstance(x, (str, list, tuple, dict, set)):
|
|
32
|
+
return len(x) > 0
|
|
29
33
|
# 使用 try-except 避免 pd.isna() 在某些类型上的歧义
|
|
30
34
|
try:
|
|
31
35
|
if pd.isna(x):
|
|
@@ -33,8 +37,6 @@ def _is_not_empty(x):
|
|
|
33
37
|
except ValueError:
|
|
34
38
|
# pd.isna() 返回数组或产生歧义时,说明有值
|
|
35
39
|
return True
|
|
36
|
-
if isinstance(x, (str, list, tuple, dict, set)):
|
|
37
|
-
return len(x) > 0
|
|
38
40
|
return True
|
|
39
41
|
|
|
40
42
|
|
|
@@ -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
|
|
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
|