tablas-python 0.1.6__py3-none-any.whl → 0.1.7__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.
tablas_python/__init__.py CHANGED
@@ -33,7 +33,7 @@ from utils.data_helpers import (
33
33
  conciliar_tablas,
34
34
  )
35
35
 
36
- __version__ = "0.1.6"
36
+ __version__ = "0.1.7"
37
37
 
38
38
  __all__ = [
39
39
  "TableManager",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tablas-python
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: Suite modular para extraer, transformar, conciliar y exportar tablas desde PDF, Excel y SQLite a pandas.
5
5
  Author: Reciba
6
6
  License: MIT
@@ -1,12 +1,12 @@
1
1
  helpers/__init__.py,sha256=BsK9M_sc93ax32ZcWPJZMkaMYeaDCiV44BYT43xF6Wk,1015
2
2
  helpers/display_helper.py,sha256=i0--Txkjc9__IIKwdkmpx98vzwM_Sekr0RzxvVGEPYA,7749
3
3
  helpers/table_manager.py,sha256=85OZqMdDqgBBJaln2ehb3-t7RWS1Gowo6aud_zqVHAo,19063
4
- tablas_python/__init__.py,sha256=Mv4si2uyD3QbZhtF_yxx7sL07kyQ1tpriTr3M-NXU-E,1807
4
+ tablas_python/__init__.py,sha256=rRl-rkkTAYNe1hf9oip0JSZXynKU6dAud-RU-EBvkvE,1807
5
5
  tablas_python/cli.py,sha256=3BModRFfT8WFkbCSxM9cF_oBK87FetPMGm5F0GTZGNo,1957
6
- tablas_python-0.1.6.dist-info/licenses/LICENSE,sha256=DQi0EoD04d2_-pnEKrC4WmcmgR6O0WQcJdvma9ILoFQ,1063
6
+ tablas_python-0.1.7.dist-info/licenses/LICENSE,sha256=DQi0EoD04d2_-pnEKrC4WmcmgR6O0WQcJdvma9ILoFQ,1063
7
7
  utils/__init__.py,sha256=jt2AT8wZrsUp45KZtNb2suIuXcGwDr0B2g9UzTE7zKU,2040
8
8
  utils/batch_processor.py,sha256=rE59qkb2sp5J0E5NU77U-CF82Aa-ukrjN2druwgS2Uk,4162
9
- utils/data_helpers.py,sha256=xjywNCZ-fIAKjxeOPkYkKDwkLUKtcbRtMuGLd1utnkE,24460
9
+ utils/data_helpers.py,sha256=PgQGIblr4gZMuK3Z83CzUcbhS0Q41JResjvHtwDYPjA,25235
10
10
  utils/excel_extractor.py,sha256=0WUhkV5eu9uUusU8zSHQB1ujFG7eQVqI-go4zqxmPFU,18364
11
11
  utils/excel_writer.py,sha256=zH_Mtu3Cr_ND_wSHKFyvzH3j16gjVoANpM3dVFXKpr0,6991
12
12
  utils/exporter.py,sha256=Oo9Y6dXTg_7t6n824xoxv8d9yuhdHZNWfwLLXvSvtMw,4661
@@ -15,8 +15,8 @@ utils/pdf_extractor.py,sha256=3JRMqnEfhBVaUOeYfiNH1rReC4EoSbzDwk919x6647w,4768
15
15
  utils/sqlite_extractor.py,sha256=mvKlKY-nsd5cV73nn3xFoqg5dgagPJceRDJfPLG0cbs,5033
16
16
  utils/table_cleaner.py,sha256=ncyiunqpVdKParFcRKwQbCqyKZgpyKRN0aUM0Oug9wU,10465
17
17
  utils/validator.py,sha256=0UywK_D510ZQCcSkhFRKhEuw48788NM_RFVC-bIFZkE,5837
18
- tablas_python-0.1.6.dist-info/METADATA,sha256=LnkQ0TZo7GFl9JUZUSX-r0wMByivt2WN_DADRngTHf8,13611
19
- tablas_python-0.1.6.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
20
- tablas_python-0.1.6.dist-info/entry_points.txt,sha256=l29nooItcUpsFzN5LmxM1b-j0qih61vJB9tX8KUwlMg,89
21
- tablas_python-0.1.6.dist-info/top_level.txt,sha256=Foud-Tbf5pviUJmp7wc3v24IjIyypkvbcZt7HkrWvss,28
22
- tablas_python-0.1.6.dist-info/RECORD,,
18
+ tablas_python-0.1.7.dist-info/METADATA,sha256=5lSqhkAWZTJanhZMN0x8BgVSGfWqxQuk5mSAmfKJgzM,13611
19
+ tablas_python-0.1.7.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
20
+ tablas_python-0.1.7.dist-info/entry_points.txt,sha256=l29nooItcUpsFzN5LmxM1b-j0qih61vJB9tX8KUwlMg,89
21
+ tablas_python-0.1.7.dist-info/top_level.txt,sha256=Foud-Tbf5pviUJmp7wc3v24IjIyypkvbcZt7HkrWvss,28
22
+ tablas_python-0.1.7.dist-info/RECORD,,
utils/data_helpers.py CHANGED
@@ -14,17 +14,20 @@ import numpy as np
14
14
  # 1. PARSEO Y LIMPIEZA DE NÚMEROS Y FECHAS
15
15
  # ==========================================
16
16
 
17
- def limpiar_numero(val: Any, default: Any = np.nan) -> Union[float, int, Any]:
17
+ def limpiar_numero(val: Any, default: Any = 0) -> Union[float, int, Any]:
18
18
  """
19
19
  Convierte cualquier valor numérico, moneda o porcentaje a float o int de forma precisa.
20
+ Si el valor está vacío, es nulo o texto sin número (ej: '-', 'N/A', 'null'), retorna 0 (o el default indicado).
21
+
20
22
  Maneja formatos latinoamericanos (1.234,56 / 0,056), anglosajones (1,234.56 / 0.056),
21
23
  símbolos ($ / € / USD / CLP / %), y negativos entre paréntesis (100) -> -100.
22
24
 
23
25
  Ejemplos:
24
26
  limpiar_numero("0,056") -> 0.056
25
- limpiar_numero("9,999") -> 9.999
26
- limpiar_numero("89,949") -> 89.949
27
- limpiar_numero("0,056%") -> 0.056
27
+ limpiar_numero("") -> 0
28
+ limpiar_numero("-") -> 0
29
+ limpiar_numero("N/A") -> 0
30
+ limpiar_numero(None) -> 0
28
31
  limpiar_numero("$ 1.250.000") -> 1250000.0
29
32
  limpiar_numero("(450,50)") -> -450.50
30
33
  """
@@ -34,7 +37,7 @@ def limpiar_numero(val: Any, default: Any = np.nan) -> Union[float, int, Any]:
34
37
  return float(val) if isinstance(val, float) else val
35
38
 
36
39
  s = str(val).strip()
37
- if not s:
40
+ if not s or s.lower() in ['', '-', '--', 'n/a', 'na', 'null', 'none', 's/i', 's/n']:
38
41
  return default
39
42
 
40
43
  # 1. Detectar negativos con paréntesis: (123.45) o (123,45)
@@ -80,6 +83,13 @@ def limpiar_numero(val: Any, default: Any = np.nan) -> Union[float, int, Any]:
80
83
  if num_puntos > 1:
81
84
  # Múltiples puntos: separador de miles latino (ej: 1.000.000)
82
85
  s = s.replace('.', '')
86
+ else:
87
+ # 1 solo punto (ej: 250.000, 39.990 vs 0.056, 12.5)
88
+ partes = s.split('.')
89
+ if len(partes) == 2:
90
+ # Si no empieza con '0' y tiene exactamente 3 dígitos tras el punto, es separador de miles (ej: 250.000)
91
+ if partes[0] not in ['0', '-0'] and len(partes[1]) == 3:
92
+ s = s.replace('.', '')
83
93
 
84
94
  try:
85
95
  num = float(s)
@@ -90,17 +100,22 @@ def limpiar_numero(val: Any, default: Any = np.nan) -> Union[float, int, Any]:
90
100
  return default
91
101
 
92
102
 
93
- def limpiar_columnas_numericas(df: pd.DataFrame, columnas: Union[str, List[str]]) -> pd.DataFrame:
103
+ def limpiar_columnas_numericas(
104
+ df: pd.DataFrame,
105
+ columnas: Union[str, List[str]],
106
+ rellenar_nulos: Any = 0
107
+ ) -> pd.DataFrame:
94
108
  """
95
- Convierte una o más columnas a tipo numérico (float) limpiando caracteres extra.
109
+ Convierte una o más columnas a tipo numérico (float) limpiando caracteres extra
110
+ y rellenando valores vacíos o nulos con 0 (o el valor indicado).
96
111
  """
97
112
  df_out = df.copy()
98
113
  if isinstance(columnas, str):
99
114
  columnas = [columnas]
100
115
  for col in columnas:
101
116
  if col in df_out.columns:
102
- df_out[col] = df_out[col].apply(limpiar_numero)
103
- df_out[col] = pd.to_numeric(df_out[col], errors='coerce')
117
+ df_out[col] = df_out[col].apply(lambda x: limpiar_numero(x, default=rellenar_nulos))
118
+ df_out[col] = pd.to_numeric(df_out[col], errors='coerce').fillna(rellenar_nulos)
104
119
  return df_out
105
120
 
106
121