Why a Large CSV Could Lose Its Nested Columns in pandas

For pandas read_csv tuple names MultiIndex 5 MB questions, start with the column contract, not just the row count. A file can contain the expected numbers while returning a different column structure. A later group selection may then fail even though the import appeared to finish normally.

This guide designs a four-case version-by-file-size check. It holds the synthetic values and parser options fixed, then asks whether the column index has the expected type, level count and selection behaviour. The matrix is proposed and unrun; it does not report results from our own pandas installation.

What pandas 3.1.2 fixes

The 30 November pandas 3.1.2 release notes list a regression fix for read_csv returning flat columns rather than a MultiIndex when tuple names were supplied on eligible files of 5 MB or more. The issue concerns column labels and their hierarchy. It is not a statement that every large CSV loses data.

The maintainer’s fix discussion describes the regression as introduced in 3.1.0: a parallel read rebuilt the labels as a flat Index of tuples instead of preserving the MultiIndex. Its example uses two tuple labels under the same x group. Selecting that group exposes a structural difference that a row-count check would miss.

Why the 5 MB detail needs a qualification

The size is a clue for planning the investigation, not a universal switch. The parallel-parser change discussion also describes row-count guards and serial fallbacks. Therefore, a file above the reported floor does not by itself establish that the relevant parallel path ran. Record the actual byte size and options, and investigate eligibility before interpreting a negative reproduction.

Use deliberately separated smaller and larger local fixtures for an initial comparison. Do not claim an exact boundary test unless the implementation’s size convention and the fixture bytes are documented. If the larger case remains on a serial path, record that limitation rather than writing that the reported regression could not exist.

Plan the pandas read_csv tuple-names MultiIndex checks

Create two isolated environments with pinned versions, such as 3.1.1 and 3.1.2. Keep the Python version, input values and read options as consistent as possible. Then record the environment before inspecting any output. A version label copied from a notebook title is weaker evidence than the version printed inside that session.

Four proposed cases cross pandas 3.1.1 and 3.1.2 with smaller and larger synthetic files; every case checks column index type, number of levels and group selection. All cases are unrun.
CHECK marks an assertion to perform, not a passing result. Larger-file eligibility must be verified separately.
VersionFixture bandChecks to retain
3.1.1Smaller local fileIndex type; nlevels; x selection
3.1.1Larger eligible local fileSame assertions; parser context
3.1.2Smaller local fileSame assertions
3.1.2Larger eligible local fileSame assertions; parser context
Proposed cases only. Observation cells in the downloadable matrix are intentionally blank.

Keep header handling and names explicit

The read_csv parameter reference distinguishes supplied names from header inference. If the file has a header row that the supplied labels replace, state header=0 explicitly. Otherwise the exercise may accidentally import its header as data, creating a separate problem that obscures the schema question.

# Proposed assertions; not executed for this article
names = [("x", "1"), ("x", "2")]
df = pd.read_csv(path, header=0, names=names, engine="c")
assert isinstance(df.columns, pd.MultiIndex)
assert df.columns.nlevels == 2
assert list(df["x"].columns) == ["1", "2"]

The example’s intended contract is a two-level column index. The assertions should run before the downstream calculation that depends on that contract. Keep the observed exception and column representation if a case fails. Do not repair the labels silently and then report the original import as a pass.

Show why a downstream operation depends on the schema

Side-by-side schema explanation: a two-level column index groups labels under x, while a flat index stores tuple labels as single entries. The x group lookup differs. Not executed output.
The two structures can carry the same displayed values. This illustration explains why a group selection needs a schema check.

For a classroom example, ask a learner to select the x group before adding its two numeric columns. If that lookup fails, separate the structural failure from the arithmetic. The numbers may be perfectly valid while the program no longer has the arrangement that the next operation expects.

Likewise, matching the number of rows does not verify the header, data types or column hierarchy. A useful import check names the properties the next step needs. Our coverage overlap exercise uses the same discipline: agree the identities and denominator before interpreting the displayed result.

Download the proposed reproduction pack

The small seed file contains invented values only. It is not a large regression fixture. Use the matrix to plan the four cases and the evidence ledger to retain actual size, version, options and observed structure. Leave the result blank until a case has run.

Method and limitations

Checked on 5 December 2026 against the release notes, API reference and linked maintainer discussions. We designed the comparison and assertion example without running pandas or building a large fixture. No speed, failure-frequency or local reproduction claim is made. Recheck the current release documentation before applying the plan to a real import.