`DataScan` and `col_summary_tbl()` don't treat NaN as missing on Polars, PyArrow and Ibis tables

Abierto
#613 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
pandas, python
Área
data

Línea de trabajo

Start by tracing DataScan's column profiling and the statistics used by col_summary_tbl(); compare how the pandas, Polars, PyArrow, and Ibis backends identify missing float values. Use the reproduction in the issue to check n_missing, the other statistics, and sample values. Done means all backends report the pandas results, with NaN counted as missing and excluded from other statistics.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

When a float column holds NaN, DataScan (and so col_summary_tbl()) gives different results depending on the backend. On pandas, NaN is counted in n_missing and left out of the other statistics, as the docs describe for missing values. On Polars, PyArrow and Ibis tables, NaN isn't counted as missing and stays in the statistics: the mean, SD and P95 become NaN, the median and Q3 shift on Polars (it sorts NaN above every number), n_unique counts NaN and null as two separate values, and nan shows up in the sample values.

Minimal reproduction:

import polars as pl
import pointblank as pb

df = pl.DataFrame({"x": [1.0, 2.0, 3.0, 4.0, float("nan"), None]})

for tbl in (df, df.to_pandas(), df.to_arrow()):
    (prof,) = pb.DataScan(tbl).profile.column_profiles
    stats = {s.name: s.val for s in prof.statistics}
    print({k: stats[k] for k in ("n_missing", "n_unique", "mean", "std", "median", "q_3", "p95")}, prof.sample_data)

Output (tidied):

polars   {'n_missing': 1, 'n_unique': 6, 'mean': nan, 'std': nan,   'median': 3.0, 'q_3': 4.0,  'p95': nan}  ['1.0', '2.0', '3.0', '4.0', 'nan']
pandas   {'n_missing': 2, 'n_unique': 5, 'mean': 2.5, 'std': 1.291, 'median': 2.5, 'q_3': 3.25, 'p95': 3.85} ['1.0', '2.0', '3.0', '4.0']
pyarrow  {'n_missing': 1, 'n_unique': 6, 'mean': nan, 'std': nan,   'median': 2.5, 'q_3': 3.25, 'p95': 3.85} ['1.0', '2.0', '3.0', '4.0', 'nan']

An Ibis table on DuckDB (ibis.memtable(df.to_arrow())) gives the same result as PyArrow, and a Polars LazyFrame the same as Polars.

Expected: the same profile on every backend, the one pandas gives. NaN counts as missing (n_missing is 2) and is left out of the other statistics, as the to_dict() docs say for a missing value ("The missing reading is counted in n_missing and left out of the other statistics"). This would also match how NaN is handled elsewhere in Pointblank, for example in missing_vals_tbl(), col_vals_null() and schema inference.

Actual: on Polars, PyArrow and Ibis tables, NaN is counted as a value. The NA column of col_summary_tbl() misses it, and Mean and SD are NaN (P95 too on Polars).

Environment: pointblank main (d82e523), Python 3.12.13, Polars 2.1.0, pandas 3.1.0, PyArrow 26.0.0, Ibis 12.0.0, DuckDB 1.5.6, Narwhals 2.28.0, macOS.

Lenguaje dominante
Python
Estrellas
506
Forks
42
Merge medio
5 h 46 min
PR fusionados (30 d)
89

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de posit-dev/pointblank

Todos los issues de posit-dev/pointblank

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.