ecodev-core 0.0.23__py3-none-any.whl → 0.0.25__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.

Potentially problematic release.


This version of ecodev-core might be problematic. Click here for more details.

ecodev_core/__init__.py CHANGED
@@ -50,8 +50,11 @@ from ecodev_core.list_utils import lselectfirst
50
50
  from ecodev_core.logger import log_critical
51
51
  from ecodev_core.logger import logger_get
52
52
  from ecodev_core.pandas_utils import get_excelfile
53
+ from ecodev_core.pandas_utils import get_value
54
+ from ecodev_core.pandas_utils import is_null
53
55
  from ecodev_core.pandas_utils import jsonify_series
54
56
  from ecodev_core.pandas_utils import pd_equals
57
+ from ecodev_core.pandas_utils import safe_drop_columns
55
58
  from ecodev_core.permissions import Permission
56
59
  from ecodev_core.pydantic_utils import Basic
57
60
  from ecodev_core.pydantic_utils import CustomFrozen
@@ -68,6 +71,7 @@ from ecodev_core.safe_utils import safe_clt
68
71
  from ecodev_core.safe_utils import SafeTestCase
69
72
  from ecodev_core.safe_utils import SimpleReturn
70
73
  from ecodev_core.safe_utils import stringify
74
+
71
75
  __all__ = [
72
76
  'AUTH', 'Token', 'get_app_services', 'attempt_to_log', 'get_current_user', 'is_admin_user',
73
77
  'write_json_file', 'load_json_file', 'make_dir', 'check_dependencies', 'compute_dependencies',
@@ -80,4 +84,4 @@ __all__ = [
80
84
  'generic_insertion', 'custom_equal', 'is_authorized_user', 'get_method', 'AppActivity',
81
85
  'fastapi_monitor', 'dash_monitor', 'is_monitoring_user', 'get_recent_activities', 'select_user',
82
86
  'get_access_token', 'safe_get_user', 'backup', 'group_by', 'get_excelfile', 'upsert_new_user',
83
- 'datify']
87
+ 'datify', 'safe_drop_columns', 'get_value', 'is_null']
@@ -4,7 +4,10 @@ Module implementing some utilitary methods on pandas types
4
4
  import tempfile
5
5
  from base64 import b64decode
6
6
  from pathlib import Path
7
+ from typing import Any
8
+ from typing import Callable
7
9
  from typing import Dict
10
+ from typing import Optional
8
11
 
9
12
  import numpy as np
10
13
  import pandas as pd
@@ -38,3 +41,29 @@ def get_excelfile(contents: str) -> pd.ExcelFile:
38
41
  content_type, content_string = contents.split(',')
39
42
  xl = b64decode(content_string)
40
43
  return pd.ExcelFile(xl)
44
+
45
+
46
+ def safe_drop_columns(df: pd.DataFrame, columns: list[str]) -> pd.DataFrame:
47
+ """
48
+ Returns a DataFrame without a list of columns, with a prior check on the existence of these
49
+ columns in the DataFrame
50
+ """
51
+
52
+ return df.drop(columns=[col for col in columns if col in df.columns])
53
+
54
+
55
+ def is_null(value: Any) -> bool:
56
+ """
57
+ Checks if a value is null or not
58
+ """
59
+ return value is None or isinstance(value, float) and np.isnan(value)
60
+
61
+
62
+ def get_value(column: str, method: Callable, row: pd.Series) -> Optional[Any]:
63
+ """
64
+ Function which performs a method on a value if the column name is in the row index
65
+ """
66
+ if column not in row.index or is_null(row[column]):
67
+ return None
68
+
69
+ return method(row[column])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ecodev-core
3
- Version: 0.0.23
3
+ Version: 0.0.25
4
4
  Summary: Low level sqlmodel/fastapi/pydantic building blocks
5
5
  License: MIT
6
6
  Author: Thomas Epelbaum
@@ -1,4 +1,4 @@
1
- ecodev_core/__init__.py,sha256=LssQSv0CD5SyuHK07j-0i_Dgawj-6tZghtzsnHTwpX0,4497
1
+ ecodev_core/__init__.py,sha256=JVtBxh-CIZQODjq4tHhl3o1qK1DqMJQsbtlFXjXBuYY,4690
2
2
  ecodev_core/app_activity.py,sha256=_rU5uPfttHxXX5IaCuTA7K9We5w2qluJ3Xpf6i12HhY,3763
3
3
  ecodev_core/app_rights.py,sha256=RZPdDtydFqc_nFj96huKAc56BS0qS6ScKv4Kghqd6lc,726
4
4
  ecodev_core/app_user.py,sha256=r1bqA4H08x53XmxmjwyGKl_PFjYQazzBbVErdkztqeE,2947
@@ -14,12 +14,12 @@ ecodev_core/db_retrieval.py,sha256=IxyF3ZtKgACLiNFggK7boKggvMRKYDRD2IimxU4dap4,7
14
14
  ecodev_core/enum_utils.py,sha256=BkQ4YQ97tXBYmMcQiSIi0mbioD5CgVU79myg1BBAXuA,556
15
15
  ecodev_core/list_utils.py,sha256=Vyws12Jv0CLdQiQl1ym0z7E6-LJTLholYHZySQxYwhM,3006
16
16
  ecodev_core/logger.py,sha256=AWGGNZz12Ql0JDq1wCJQxwxK2syiczEBftmuJkjbAPw,3149
17
- ecodev_core/pandas_utils.py,sha256=bkobhqj_tWrFCgBGQwPJLwN59HJunNDeBKhnctWCUBE,1364
17
+ ecodev_core/pandas_utils.py,sha256=Juc6gvPnoBiSVF2SR6_vfMi5W-QEkY3fnpo5ROB1L9s,2191
18
18
  ecodev_core/permissions.py,sha256=WAx-ilMu8LlQp2sjJVdkhNQieytEaEm8577ZF1HWeTY,502
19
19
  ecodev_core/pydantic_utils.py,sha256=e3GH50JmcpTmd2UgrB94QSwWOlOCW3WIlVdyX9C4T-U,741
20
20
  ecodev_core/read_write.py,sha256=auJ5bBJTVGkLRkiP_vZxVCX64B0Y-9qpsaDhovHmbas,996
21
21
  ecodev_core/safe_utils.py,sha256=JCfxo6fcznjsL-XHNJ1TKo1UvfJB83WT5jpTFmtJwsE,6160
22
- ecodev_core-0.0.23.dist-info/LICENSE.md,sha256=jebQDe1ib9LAODuNvcSoo2CoqS6P0_q8--mMTICh_kI,1074
23
- ecodev_core-0.0.23.dist-info/METADATA,sha256=jkgox1PQWpL9JpwXbEGxVERQq4ofoyfQ5Bn8me32S1k,3276
24
- ecodev_core-0.0.23.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
25
- ecodev_core-0.0.23.dist-info/RECORD,,
22
+ ecodev_core-0.0.25.dist-info/LICENSE.md,sha256=jebQDe1ib9LAODuNvcSoo2CoqS6P0_q8--mMTICh_kI,1074
23
+ ecodev_core-0.0.25.dist-info/METADATA,sha256=2i-cjkxDoS1j822e7p8TpWwibG95Vuy-otzuFGOUr80,3276
24
+ ecodev_core-0.0.25.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
25
+ ecodev_core-0.0.25.dist-info/RECORD,,