tablas-python 0.1.4__py3-none-any.whl → 0.1.6__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.
- helpers/__init__.py +4 -1
- tablas_python/__init__.py +3 -1
- {tablas_python-0.1.4.dist-info → tablas_python-0.1.6.dist-info}/METADATA +1 -1
- {tablas_python-0.1.4.dist-info → tablas_python-0.1.6.dist-info}/RECORD +10 -10
- utils/__init__.py +2 -0
- utils/data_helpers.py +48 -27
- {tablas_python-0.1.4.dist-info → tablas_python-0.1.6.dist-info}/WHEEL +0 -0
- {tablas_python-0.1.4.dist-info → tablas_python-0.1.6.dist-info}/entry_points.txt +0 -0
- {tablas_python-0.1.4.dist-info → tablas_python-0.1.6.dist-info}/licenses/LICENSE +0 -0
- {tablas_python-0.1.4.dist-info → tablas_python-0.1.6.dist-info}/top_level.txt +0 -0
helpers/__init__.py
CHANGED
|
@@ -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
|
]
|
tablas_python/__init__.py
CHANGED
|
@@ -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.6"
|
|
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",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
helpers/__init__.py,sha256=
|
|
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=
|
|
4
|
+
tablas_python/__init__.py,sha256=Mv4si2uyD3QbZhtF_yxx7sL07kyQ1tpriTr3M-NXU-E,1807
|
|
5
5
|
tablas_python/cli.py,sha256=3BModRFfT8WFkbCSxM9cF_oBK87FetPMGm5F0GTZGNo,1957
|
|
6
|
-
tablas_python-0.1.
|
|
7
|
-
utils/__init__.py,sha256=
|
|
6
|
+
tablas_python-0.1.6.dist-info/licenses/LICENSE,sha256=DQi0EoD04d2_-pnEKrC4WmcmgR6O0WQcJdvma9ILoFQ,1063
|
|
7
|
+
utils/__init__.py,sha256=jt2AT8wZrsUp45KZtNb2suIuXcGwDr0B2g9UzTE7zKU,2040
|
|
8
8
|
utils/batch_processor.py,sha256=rE59qkb2sp5J0E5NU77U-CF82Aa-ukrjN2druwgS2Uk,4162
|
|
9
|
-
utils/data_helpers.py,sha256=
|
|
9
|
+
utils/data_helpers.py,sha256=xjywNCZ-fIAKjxeOPkYkKDwkLUKtcbRtMuGLd1utnkE,24460
|
|
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.
|
|
19
|
-
tablas_python-0.1.
|
|
20
|
-
tablas_python-0.1.
|
|
21
|
-
tablas_python-0.1.
|
|
22
|
-
tablas_python-0.1.
|
|
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,,
|
utils/__init__.py
CHANGED
|
@@ -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",
|
utils/data_helpers.py
CHANGED
|
@@ -14,27 +14,30 @@ 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) -> Union[float, int, Any]:
|
|
17
|
+
def limpiar_numero(val: Any, default: Any = np.nan) -> Union[float, int, Any]:
|
|
18
18
|
"""
|
|
19
|
-
Convierte cualquier
|
|
20
|
-
Maneja formatos latinoamericanos (1.234,56)
|
|
19
|
+
Convierte cualquier valor numérico, moneda o porcentaje a float o int de forma precisa.
|
|
20
|
+
Maneja formatos latinoamericanos (1.234,56 / 0,056), anglosajones (1,234.56 / 0.056),
|
|
21
21
|
símbolos ($ / € / USD / CLP / %), y negativos entre paréntesis (100) -> -100.
|
|
22
22
|
|
|
23
23
|
Ejemplos:
|
|
24
|
+
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
|
|
24
28
|
limpiar_numero("$ 1.250.000") -> 1250000.0
|
|
25
|
-
limpiar_numero("
|
|
26
|
-
limpiar_numero("(450.50)") -> -450.50
|
|
29
|
+
limpiar_numero("(450,50)") -> -450.50
|
|
27
30
|
"""
|
|
28
31
|
if pd.isna(val) or val is None:
|
|
29
|
-
return
|
|
32
|
+
return default
|
|
30
33
|
if isinstance(val, (int, float, np.number)):
|
|
31
|
-
return val
|
|
34
|
+
return float(val) if isinstance(val, float) else val
|
|
32
35
|
|
|
33
36
|
s = str(val).strip()
|
|
34
37
|
if not s:
|
|
35
|
-
return
|
|
38
|
+
return default
|
|
36
39
|
|
|
37
|
-
# Detectar negativos con paréntesis: (123.45)
|
|
40
|
+
# 1. Detectar negativos con paréntesis: (123.45) o (123,45)
|
|
38
41
|
es_negativo = False
|
|
39
42
|
if s.startswith("(") and s.endswith(")"):
|
|
40
43
|
es_negativo = True
|
|
@@ -43,46 +46,48 @@ def limpiar_numero(val: Any) -> Union[float, int, Any]:
|
|
|
43
46
|
es_negativo = True
|
|
44
47
|
s = s[1:].strip()
|
|
45
48
|
|
|
46
|
-
# Remover símbolos de monedas y
|
|
49
|
+
# 2. Remover símbolos de monedas y texto innecesario
|
|
47
50
|
s = re.sub(r'[\$\€\£\¥\s]|USD|CLP|EUR|UF', '', s, flags=re.IGNORECASE)
|
|
48
51
|
# Remover %
|
|
49
52
|
s = s.replace('%', '').strip()
|
|
50
53
|
|
|
51
54
|
if not s:
|
|
52
|
-
return
|
|
55
|
+
return default
|
|
53
56
|
|
|
54
|
-
# Determinar
|
|
55
|
-
# Caso
|
|
57
|
+
# 3. Determinar separadores decimales y de miles
|
|
58
|
+
# Caso A: Tiene comas y puntos (ej: 1.234.567,89 o 1,234,567.89)
|
|
56
59
|
if '.' in s and ',' in s:
|
|
57
60
|
if s.rfind(',') > s.rfind('.'):
|
|
58
|
-
# Formato latino: 1.234,
|
|
61
|
+
# Formato latino: 1.234.567,89 -> quitar puntos y reemplazar coma por punto
|
|
59
62
|
s = s.replace('.', '').replace(',', '.')
|
|
60
63
|
else:
|
|
61
|
-
# Formato anglo: 1,234.
|
|
64
|
+
# Formato anglo: 1,234,567.89 -> quitar comas
|
|
62
65
|
s = s.replace(',', '')
|
|
66
|
+
|
|
67
|
+
# Caso B: Solo tiene coma(s)
|
|
63
68
|
elif ',' in s:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
num_comas = s.count(',')
|
|
70
|
+
if num_comas == 1:
|
|
71
|
+
# 1 sola coma: SIEMPRE es separador decimal en español (ej: 0,056 | 9,999 | 89,949 | 123,45)
|
|
67
72
|
s = s.replace(',', '.')
|
|
68
73
|
else:
|
|
69
|
-
#
|
|
74
|
+
# Múltiples comas: separador de miles anglosajón (ej: 1,000,000)
|
|
70
75
|
s = s.replace(',', '')
|
|
76
|
+
|
|
77
|
+
# Caso C: Solo tiene punto(s)
|
|
71
78
|
elif '.' in s:
|
|
72
|
-
|
|
73
|
-
if
|
|
79
|
+
num_puntos = s.count('.')
|
|
80
|
+
if num_puntos > 1:
|
|
81
|
+
# Múltiples puntos: separador de miles latino (ej: 1.000.000)
|
|
74
82
|
s = s.replace('.', '')
|
|
75
|
-
# Si tiene 1 punto y exactamente 3 dígitos después, puede ser miles (ej: 1.500)
|
|
76
|
-
# pero en float estándar suele ser decimal. Lo dejamos a float directo.
|
|
77
83
|
|
|
78
84
|
try:
|
|
79
85
|
num = float(s)
|
|
80
86
|
if es_negativo:
|
|
81
87
|
num = -num
|
|
82
|
-
# Si no tiene decimales reales, retornar float o int
|
|
83
88
|
return num
|
|
84
89
|
except ValueError:
|
|
85
|
-
return
|
|
90
|
+
return default
|
|
86
91
|
|
|
87
92
|
|
|
88
93
|
def limpiar_columnas_numericas(df: pd.DataFrame, columnas: Union[str, List[str]]) -> pd.DataFrame:
|
|
@@ -141,6 +146,18 @@ def formato_moneda(val: Any, simbolo: str = "$", decimales: int = 0, separador_m
|
|
|
141
146
|
return f"{simbolo} {texto}" if simbolo else texto
|
|
142
147
|
|
|
143
148
|
|
|
149
|
+
def formato_clp(val: Any, simbolo: str = "$") -> str:
|
|
150
|
+
"""
|
|
151
|
+
Formatea un número o texto a Pesos Chilenos (CLP) con separador de miles y sin decimales.
|
|
152
|
+
|
|
153
|
+
Ejemplos:
|
|
154
|
+
formato_clp(1500000) -> "$ 1.500.000"
|
|
155
|
+
formato_clp("1500000") -> "$ 1.500.000"
|
|
156
|
+
formato_clp(250000, simbolo="CLP") -> "CLP 250.000"
|
|
157
|
+
"""
|
|
158
|
+
return formato_moneda(val, simbolo=simbolo, decimales=0, separador_miles=".")
|
|
159
|
+
|
|
160
|
+
|
|
144
161
|
def formato_porcentaje(
|
|
145
162
|
val: Any,
|
|
146
163
|
decimales: Optional[int] = None,
|
|
@@ -219,10 +236,14 @@ def formatear_dataframe(
|
|
|
219
236
|
for col, tipo in reglas.items():
|
|
220
237
|
if col not in df_out.columns:
|
|
221
238
|
continue
|
|
222
|
-
if tipo
|
|
223
|
-
df_out[col] = df_out[col].apply(lambda x:
|
|
239
|
+
if tipo in ['moneda', 'clp', 'moneda_clp']:
|
|
240
|
+
df_out[col] = df_out[col].apply(lambda x: formato_clp(x))
|
|
224
241
|
elif tipo == 'moneda_2dec':
|
|
225
242
|
df_out[col] = df_out[col].apply(lambda x: formato_moneda(x, decimales=2))
|
|
243
|
+
elif tipo == 'usd':
|
|
244
|
+
df_out[col] = df_out[col].apply(lambda x: formato_moneda(x, simbolo="USD $", decimales=2, separador_miles=","))
|
|
245
|
+
elif tipo == 'uf':
|
|
246
|
+
df_out[col] = df_out[col].apply(lambda x: formato_moneda(x, simbolo="UF", decimales=2, separador_miles="."))
|
|
226
247
|
elif tipo == 'porcentaje':
|
|
227
248
|
df_out[col] = df_out[col].apply(lambda x: formato_porcentaje(x))
|
|
228
249
|
elif tipo == 'porcentaje_1dec':
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|