tablas-python 0.1.5__tar.gz → 0.1.7__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.
- {tablas_python-0.1.5 → tablas_python-0.1.7}/PKG-INFO +1 -1
- {tablas_python-0.1.5 → tablas_python-0.1.7}/helpers/__init__.py +4 -1
- {tablas_python-0.1.5 → tablas_python-0.1.7}/pyproject.toml +1 -1
- {tablas_python-0.1.5 → tablas_python-0.1.7}/tablas_python/__init__.py +3 -1
- {tablas_python-0.1.5 → tablas_python-0.1.7}/tablas_python.egg-info/PKG-INFO +1 -1
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/__init__.py +2 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/data_helpers.py +42 -11
- {tablas_python-0.1.5 → tablas_python-0.1.7}/LICENSE +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/README.md +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/helpers/display_helper.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/helpers/table_manager.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/setup.cfg +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/tablas_python/cli.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/tablas_python.egg-info/SOURCES.txt +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/tablas_python.egg-info/dependency_links.txt +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/tablas_python.egg-info/entry_points.txt +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/tablas_python.egg-info/requires.txt +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/tablas_python.egg-info/top_level.txt +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/batch_processor.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/excel_extractor.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/excel_writer.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/exporter.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/file_utils.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/pdf_extractor.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/sqlite_extractor.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/table_cleaner.py +0 -0
- {tablas_python-0.1.5 → tablas_python-0.1.7}/utils/validator.py +0 -0
|
@@ -7,7 +7,7 @@ from .display_helper import DisplayHelper, mostrar_tabla
|
|
|
7
7
|
from utils.batch_processor import unir_archivos_carpeta
|
|
8
8
|
from utils.excel_writer import escribir_en_excel
|
|
9
9
|
from utils.validator import validar_dataframe, reporte_calidad, detectar_duplicados
|
|
10
|
-
from utils.data_helpers import buscar_v, conciliar_tablas, obtener_celda, modificar_celda
|
|
10
|
+
from utils.data_helpers import buscar_v, conciliar_tablas, obtener_celda, modificar_celda, formato_clp, formato_porcentaje, formato_moneda
|
|
11
11
|
|
|
12
12
|
__all__ = [
|
|
13
13
|
"TableManager",
|
|
@@ -23,6 +23,9 @@ __all__ = [
|
|
|
23
23
|
"conciliar_tablas",
|
|
24
24
|
"obtener_celda",
|
|
25
25
|
"modificar_celda",
|
|
26
|
+
"formato_clp",
|
|
27
|
+
"formato_porcentaje",
|
|
28
|
+
"formato_moneda",
|
|
26
29
|
"DisplayHelper",
|
|
27
30
|
"mostrar_tabla",
|
|
28
31
|
]
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tablas-python"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.7"
|
|
8
8
|
description = "Suite modular para extraer, transformar, conciliar y exportar tablas desde PDF, Excel y SQLite a pandas."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
@@ -18,6 +18,7 @@ from utils.data_helpers import (
|
|
|
18
18
|
limpiar_columnas_numericas,
|
|
19
19
|
normalizar_fechas,
|
|
20
20
|
formato_moneda,
|
|
21
|
+
formato_clp,
|
|
21
22
|
formato_porcentaje,
|
|
22
23
|
formato_miles,
|
|
23
24
|
formatear_dataframe,
|
|
@@ -32,7 +33,7 @@ from utils.data_helpers import (
|
|
|
32
33
|
conciliar_tablas,
|
|
33
34
|
)
|
|
34
35
|
|
|
35
|
-
__version__ = "0.1.
|
|
36
|
+
__version__ = "0.1.7"
|
|
36
37
|
|
|
37
38
|
__all__ = [
|
|
38
39
|
"TableManager",
|
|
@@ -54,6 +55,7 @@ __all__ = [
|
|
|
54
55
|
"limpiar_columnas_numericas",
|
|
55
56
|
"normalizar_fechas",
|
|
56
57
|
"formato_moneda",
|
|
58
|
+
"formato_clp",
|
|
57
59
|
"formato_porcentaje",
|
|
58
60
|
"formato_miles",
|
|
59
61
|
"formatear_dataframe",
|
|
@@ -17,6 +17,7 @@ from .data_helpers import (
|
|
|
17
17
|
limpiar_columnas_numericas,
|
|
18
18
|
normalizar_fechas,
|
|
19
19
|
formato_moneda,
|
|
20
|
+
formato_clp,
|
|
20
21
|
formato_porcentaje,
|
|
21
22
|
formato_miles,
|
|
22
23
|
formatear_dataframe,
|
|
@@ -56,6 +57,7 @@ __all__ = [
|
|
|
56
57
|
"limpiar_columnas_numericas",
|
|
57
58
|
"normalizar_fechas",
|
|
58
59
|
"formato_moneda",
|
|
60
|
+
"formato_clp",
|
|
59
61
|
"formato_porcentaje",
|
|
60
62
|
"formato_miles",
|
|
61
63
|
"formatear_dataframe",
|
|
@@ -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 =
|
|
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("
|
|
26
|
-
limpiar_numero("
|
|
27
|
-
limpiar_numero("
|
|
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(
|
|
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
|
|
|
@@ -146,6 +161,18 @@ def formato_moneda(val: Any, simbolo: str = "$", decimales: int = 0, separador_m
|
|
|
146
161
|
return f"{simbolo} {texto}" if simbolo else texto
|
|
147
162
|
|
|
148
163
|
|
|
164
|
+
def formato_clp(val: Any, simbolo: str = "$") -> str:
|
|
165
|
+
"""
|
|
166
|
+
Formatea un número o texto a Pesos Chilenos (CLP) con separador de miles y sin decimales.
|
|
167
|
+
|
|
168
|
+
Ejemplos:
|
|
169
|
+
formato_clp(1500000) -> "$ 1.500.000"
|
|
170
|
+
formato_clp("1500000") -> "$ 1.500.000"
|
|
171
|
+
formato_clp(250000, simbolo="CLP") -> "CLP 250.000"
|
|
172
|
+
"""
|
|
173
|
+
return formato_moneda(val, simbolo=simbolo, decimales=0, separador_miles=".")
|
|
174
|
+
|
|
175
|
+
|
|
149
176
|
def formato_porcentaje(
|
|
150
177
|
val: Any,
|
|
151
178
|
decimales: Optional[int] = None,
|
|
@@ -224,10 +251,14 @@ def formatear_dataframe(
|
|
|
224
251
|
for col, tipo in reglas.items():
|
|
225
252
|
if col not in df_out.columns:
|
|
226
253
|
continue
|
|
227
|
-
if tipo
|
|
228
|
-
df_out[col] = df_out[col].apply(lambda x:
|
|
254
|
+
if tipo in ['moneda', 'clp', 'moneda_clp']:
|
|
255
|
+
df_out[col] = df_out[col].apply(lambda x: formato_clp(x))
|
|
229
256
|
elif tipo == 'moneda_2dec':
|
|
230
257
|
df_out[col] = df_out[col].apply(lambda x: formato_moneda(x, decimales=2))
|
|
258
|
+
elif tipo == 'usd':
|
|
259
|
+
df_out[col] = df_out[col].apply(lambda x: formato_moneda(x, simbolo="USD $", decimales=2, separador_miles=","))
|
|
260
|
+
elif tipo == 'uf':
|
|
261
|
+
df_out[col] = df_out[col].apply(lambda x: formato_moneda(x, simbolo="UF", decimales=2, separador_miles="."))
|
|
231
262
|
elif tipo == 'porcentaje':
|
|
232
263
|
df_out[col] = df_out[col].apply(lambda x: formato_porcentaje(x))
|
|
233
264
|
elif tipo == 'porcentaje_1dec':
|
|
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
|