Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/update_eph_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Instalar paquetes R
run: |
install.packages(c("dplyr", "arrow", "eph", "glue", "purrr", "readr", "assertthat", "stringr"))
install.packages(c("dplyr", "arrow", "eph", "glue", "purrr", "readr", "assertthat", "stringr", "testthat"))
shell: Rscript {0}

- name: Ejecutar script de actualización
Expand Down Expand Up @@ -79,6 +79,14 @@ jobs:
if: steps.check.outputs.has_new == 'true'
run: Rscript ETL/09b-build_paneles_runtime_anual.R

### Gate de validación (issue #45). Si los parquets recién regenerados
### tienen drift de schema, gaps de cobertura, dúos con n anómalo o
### las tasas no coinciden con los CSVs históricos, abortamos antes
### de crear el PR. Evita propagar regresiones silenciosas a prod.
- name: Validar parquets de runtime
if: steps.check.outputs.has_new == 'true'
run: Rscript ETL/12-validate_paneles_runtime.R

- name: Limpiar archivo temporal antes del commit
if: steps.check.outputs.has_new == 'true'
run: rm -f .new_periods.txt
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,28 @@ versionado [SemVer](https://semver.org/lang/es/) adaptado a app web:

## [Unreleased]

### Changed

- Sprint B · Calidad técnica (#39, scope acotado): pasada de
anti-patterns dplyr/purrr en todo el repo. `pmap_dfr` / `map_dfr`
reemplazados por `pmap()/map() |> list_rbind()` (10 ocurrencias en
ETL/04b, 05, 06, 07 y 99-functions). `group_by(X) |> mutate(...) |> ungroup()`
reemplazado por `mutate(..., .by = X)` en `preparo_base()` (2 casos).
`%>%` magrittr reemplazado por `|>` nativo en `df_to_annotations_labels()`
(3 líneas). Refactor sin cambio funcional: los 185 tests pasan igual.

### Added

- Sprint B · Calidad técnica (#45): script `ETL/12-validate_paneles_runtime.R`
con 29 validaciones testthat sobre los parquets de runtime
(intertrim + anual). Cubre schema (31 cols + tipos), cobertura
temporal (≥75 dúos trim / ≥65 anual, empieza 2003-T3), tamaño y
atrición (n>5000 por dúo, ratio anual/trim ∈ [40%, 120%]), y
cross-validation de tasas (CSV histórico vs recálculo on-demand,
tolerancia 0.5 pp). Integrado al workflow `update_eph_data.yml`
como gate después de regenerar los parquets y antes de crear el PR.
Si alguna validación falla, el workflow aborta y prod no recibe
datos corruptos.
- Sprint test-1 batch 3: tests para `arma_matriz_transicion`,
`build_tasas_historico`, `regenerar_calidad_panel`, `formato_delta`,
`sankey_label_legible`, `sankey_nodes_orden`. Suite de testthat pasa
Expand Down
3 changes: 2 additions & 1 deletion ETL/04b-add_pp05_vars.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ descargar_pp05 <- function(anio, trim) {
}

descargas <- periodos_target |>
pmap_dfr(function(ANO4, TRIMESTRE) descargar_pp05(ANO4, TRIMESTRE))
pmap(function(ANO4, TRIMESTRE) descargar_pp05(ANO4, TRIMESTRE)) |>
list_rbind()

cat("\nDescargas totales:", nrow(descargas), "filas\n")

Expand Down
10 changes: 6 additions & 4 deletions ETL/05-build_panel_cat_ocup.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ etiquetas_cat_ocup <- c("Patron", "Cuenta_propia", "Asalariado", "TFSR")
categorias_sankey <- etiquetas_cat_ocup ### las 4 producen una vista del Sankey

paneles_nuevos <- paneles |>
pmap_dfr(function(ANO4, TRIMESTRE, anio_post, trim_post, periodo, ...) {
pmap(function(ANO4, TRIMESTRE, anio_post, trim_post, periodo, ...) {
cat(glue(" panel {periodo}... "))

df_panel <- armo_base_panel(
Expand All @@ -70,16 +70,18 @@ paneles_nuevos <- paneles |>
etiquetas = etiquetas_cat_ocup
)

res <- map_dfr(categorias_sankey, function(cat) {
res <- map(categorias_sankey, function(cat) {
tryCatch({
armo_tabla_sankey(table = df_prep, categoria = cat) |>
mutate(periodo = as.character(periodo))
}, error = function(e) tibble())
})
}) |>
list_rbind()

cat(nrow(res), "filas\n")
res
})
}) |>
list_rbind()

cat("\nFilas totales:", nrow(paneles_nuevos), "\n")

Expand Down
10 changes: 6 additions & 4 deletions ETL/06-build_panel_formalidad.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ etiquetas_formalidad <- c("Formal", "Informal")
categorias_sankey <- etiquetas_formalidad

paneles_nuevos <- paneles |>
pmap_dfr(function(ANO4, TRIMESTRE, anio_post, trim_post, periodo, ...) {
pmap(function(ANO4, TRIMESTRE, anio_post, trim_post, periodo, ...) {
cat(glue(" panel {periodo}... "))

df_panel <- armo_base_panel(
Expand All @@ -63,16 +63,18 @@ paneles_nuevos <- paneles |>
etiquetas = etiquetas_formalidad
)

res <- map_dfr(categorias_sankey, function(cat) {
res <- map(categorias_sankey, function(cat) {
tryCatch({
armo_tabla_sankey(table = df_prep, categoria = cat) |>
mutate(periodo = as.character(periodo))
}, error = function(e) tibble())
})
}) |>
list_rbind()

cat(nrow(res), "filas\n")
res
})
}) |>
list_rbind()

cat("\nFilas totales:", nrow(paneles_nuevos), "\n")

Expand Down
10 changes: 6 additions & 4 deletions ETL/07-build_panel_formalidad_ampliada.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ etiquetas_formalidad <- c("Formal", "Informal")
categorias_sankey <- etiquetas_formalidad

paneles_nuevos <- paneles |>
pmap_dfr(function(ANO4, TRIMESTRE, anio_post, trim_post, periodo, ...) {
pmap(function(ANO4, TRIMESTRE, anio_post, trim_post, periodo, ...) {
cat(glue(" panel {periodo}... "))

df_panel <- armo_base_panel(
Expand All @@ -68,16 +68,18 @@ paneles_nuevos <- paneles |>
etiquetas = etiquetas_formalidad
)

res <- map_dfr(categorias_sankey, function(cat) {
res <- map(categorias_sankey, function(cat) {
tryCatch({
armo_tabla_sankey(table = df_prep, categoria = cat) |>
mutate(periodo = as.character(periodo))
}, error = function(e) tibble())
})
}) |>
list_rbind()

cat(nrow(res), "filas\n")
res
})
}) |>
list_rbind()

cat("\nFilas totales:", nrow(paneles_nuevos), "\n")

Expand Down
Loading
Loading