Skip to content

A column mixing the number 1 and the string "1" gives two groups with the same label in Python and one group in JS #993

Closed

Description

@yakew7

Where: faircode/profiler.py _dimension() (col.dropna().value_counts(), line 335), assets/profiler-engine.js nunique() / the group counter, tests/test_json_edge_cases.py.

Current gap: value_counts() keeps the integer 1 and the string "1" apart, then _analyze_groups() stringifies the labels, so the report lists 1 twice. JS keys groups by their string form and shows one 1 group with the combined count. A JSON column that mixes types (common when one exporter quotes some numbers) is therefore profiled differently by the two engines, and the Python report has two rows a person cannot tell apart.

Repro:

$ python3 - <<'E'
import json, tempfile, os
from faircode.loaders_extra import read_table
from faircode import profile
p = os.path.join(tempfile.mkdtemp(), "m.json")
open(p, "w").write(json.dumps([{"race": v} for v in [1, "1", "a", "b"] * 10]))
print([(g["label"], g["count"]) for g in profile(read_table(p), {"race": "race"})["dimensions"][0]["groups"]])
E
[('1', 10), ('1', 10), ('a', 10), ('b', 10)]      # JS: [('1', 20), ('a', 10), ('b', 10)]

Suggested approach: convert the column to strings before counting (after dropping nulls), so both engines key on the same text, and add a mixed-type JSON file to the parity tests.

Activity

  1. pinned this issue on Oct 15, 2026
  2. yakew7 commented on Oct 16, 2026

    @yakew7
    OwnerAuthor

    Fixed in 0a3bb6d (on main). Full suite green (941 passed).

  3. unpinned this issue on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions