Spaces:
Runtime error
Runtime error
import pandas as pd | |
import plotly.express as px | |
# Valores de Junio 2022 | |
TRAMOS = { | |
777000: 0, | |
1727000: 0.04, | |
2878000: 0.08, | |
4029000: 0.135, | |
5180000: 0.23, | |
6906000: 0.304, | |
17842000: 0.35, | |
99999999: 0.4, | |
} | |
TRAMOS_REFORMA = { | |
777000: 0, | |
1727000: 0.04, | |
2878000: 0.08, | |
4030000: 0.135, | |
5242320: 0.26, | |
6331000: 0.35, | |
8057000: 0.40, | |
99999999: 0.43, | |
} | |
def descomponer_en_tramos(sueldo_bruto, tramos=TRAMOS): | |
""" | |
Descompone un sueldo bruto en tramos de impuesto | |
""" | |
descomp = [] | |
impuestos = [] | |
tramo_anterior = 0 | |
for tramo, descuento in tramos.items(): | |
delta = min(sueldo_bruto, tramo) - tramo_anterior | |
if delta > 0: | |
descomp.append(delta) | |
impuestos.append(int(delta * descuento)) | |
tramo_anterior = tramo | |
return descomp, impuestos | |
def get_table(sueldo_bruto, tramos=TRAMOS): | |
""" | |
Tabla de Impuestos por tramo | |
""" | |
_tramos = [0] + list(tramos.keys()) | |
tasas = tramos.values() | |
data = list( | |
zip( | |
_tramos[:-1], | |
_tramos[1:], | |
tasas, | |
*descomponer_en_tramos(sueldo_bruto, tramos), | |
) | |
) | |
df = pd.DataFrame( | |
data=data, | |
columns=["Desde", "Hasta", "Tasa", "Monto", "Impuesto"], | |
) | |
style = df.style.format( | |
{ | |
"Desde": "{:,d}", | |
"Hasta": "{:,d}", | |
"Tasa": "{:.2f}", | |
"Monto": "{:,d}", | |
"Impuesto": "{:,d}", | |
}, | |
decimal=",", | |
thousands=".", | |
) | |
return df, style | |
salarios = [ | |
500_000, | |
750_000, | |
] + [1_000_000 * i for i in range(20)] | |
def get_curve(descuentos): | |
def beneficios(s): | |
return max(s - descuentos, 0) | |
DF_CURVA = pd.DataFrame(columns=["actual", "reforma"], index=salarios) | |
DF_CURVA["actual"] = [sum(descomponer_en_tramos(s, TRAMOS)[1]) for s in salarios] | |
DF_CURVA["reforma"] = [ | |
sum(descomponer_en_tramos(beneficios(s), TRAMOS_REFORMA)[1]) for s in salarios | |
] | |
return px.line( | |
DF_CURVA, | |
title="Impuesto con respecto al salario", | |
labels={"value": "Impuesto a pagar", "index": "Renta mensual"}, | |
) | |