Skip to content

B2b: Table, dataframe, JSON and array codecs #91

Closed

Description

@Claptar

Part of #87.

wave 1 · 0.17.4 · size L · starts after: nothing (rebase on 0.17.3: it touched formats/table.py)

Goal. import and export keep values and types the way pandas and anndata do, and never replace a group they were not asked to replace.

Owns: formats/{table,dataframe,sparse,json_data,array}.py, tests/test_import.py, tests/test_table.py, tests/test_formats.py

Approach:

  • Type numbers with explicit regexes, not int()/float(), so 1_1 stays text (F020). Keep each column's kind across blocks (F068). Integers past int64 become uint64 or object, as pandas does (F069).
  • import dataframe (F018, F034):
    • missing cells become nullable numbers, not strings;
    • short rows are refused;
    • the CSV is streamed through table.py, not list(reader).
  • import array/sparse/dict refuse to overwrite a dataframe or mapping group unless it is replaced explicitly (F019).
  • JSON:
    • null never becomes encoding-type: null (F035);
    • mixed or nullable arrays are typed, or refused (F067);
    • export dict writes null for NaN and Infinity (F128).
  • Export (F063, F064, F080, F065, F127):
    • export array keeps masks and handles text;
    • it writes by streaming rather than through a memmap;
    • export dataframe validates --columns before opening the output;
    • it handles a broken pipe cleanly.
  • Oracle: read every import and export result back with anndata and pandas (F089).

Findings

Ref Sev Finding Where
F018 H import dataframe: numeric columns with any missing cell become strings; short rows silently become NaN; bools become categoricals src/adata/formats/dataframe.py:150
F019 H import array/sparse/dict replace dataframe and mapping groups (obs, var, obsm, layers) with an array: exit 0, store unreadable src/adata/formats/sparse.py:121
F020 H CSV numeric typing accepts Python-only literals: labels like '1_1' become the integer 11 ('1_10' and '11_0' both become 110) src/adata/formats/table.py:148
F034 H import dataframe and import array hold the whole input in memory (not bounded by --chunk) src/adata/formats/dataframe.py:131
F035 H import dict with a JSON null writes encoding-type: null, which anndata 0.8 to 0.11 refuse, so one null makes the whole store unreadable src/adata/formats/json_data.py:153
F063 M export array of a nullable-integer/boolean column drops the mask: missing entries are exported as 0/False src/adata/formats/array.py:34
F064 M export array cannot export any text array and fails with a misleading memmap error, even for the nullable-string-array it claims to handle src/adata/formats/array.py:43
F065 M export dataframe checks --columns only while writing, leaving a header-only CSV on refusal src/adata/formats/dataframe.py:74
F067 M import dict stringifies mixed or nullable JSON arrays via Python str(), writes >64-bit ints that make the store unreadable, and mangles '/' … src/adata/formats/json_data.py:171
F068 M Column narrowing restarts per block from the current kind: True/False blocks followed by integer blocks are typed int64, then pass 2 crashes src/adata/formats/table.py:141
F069 M table.py types integers beyond int64 as float64 and silently loses precision (pandas reads them as uint64 or text) src/adata/formats/table.py:152
F080 M export array -o writes through a writable memmap, so peak RSS equals the whole output array, unseen by the tracemalloc guard src/adata/formats/array.py:54
F089 M import/export/format tests never read their results with anndata or pandas, only with h5py presence and shape checks tests/test_import.py:23
F127 L Export to stdout: broken pipe on | head reports Error and exits 1; CSV lines end in CRLF; --head 0 exports everything src/adata/formats/dataframe.py:75
F128 L export dict writes NaN/Infinity tokens, which is invalid JSON src/adata/formats/json_data.py:45

Done when one PR on fix/b2b closes this, with a regression test against an oracle for every finding, and docs and changelog in the same PR.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions