hankcs/HanLP · warning

As you did not pass in `headers` to `TableDataset`, the firs

Error message

As you did not pass in `headers` to `TableDataset`, the first line is regarded as headers. However, the length for some headers are too long (>32), which might be wrong. To make sure, pass `headers=...` explicitly.

What it means

TableDataset.load_file warns when, without explicit headers, it takes the first CSV/TSV line as column headers and some header string is longer than 32 chars — a heuristic suggesting the first line is actually data, not headers.

Source

Thrown at hanlp/common/dataset.py:836

class TableDataset(TransformableDataset):
    def __init__(self,
                 data: Union[str, List],
                 transform: Union[Callable, List] = None,
                 cache=None,
                 delimiter='auto',
                 strip=True,
                 headers=None) -> None:
        self.headers = headers
        self.strip = strip
        self.delimiter = delimiter
        super().__init__(data, transform, cache)

    def load_file(self, filepath: str):
        for idx, cells in enumerate(read_cells(filepath, strip=self.strip, delimiter=self.delimiter)):
            if not idx and not self.headers:
                self.headers = cells
                if any(len(h) > 32 for h in self.headers):
                    warnings.warn('As you did not pass in `headers` to `TableDataset`, the first line is regarded as '
                                  'headers. However, the length for some headers are too long (>32), which might be '
                                  'wrong. To make sure, pass `headers=...` explicitly.')
            else:
                yield dict(zip(self.headers, cells))

View on GitHub (pinned to ddb1299bdd)

Solutions

  1. Pass headers=[...] explicitly so the first line is treated as data
  2. Verify self.delimiter matches the file's actual delimiter
  3. If the file truly has headers, ignore the warning or shorten header names

Example fix

# before
ds = TableDataset('data.tsv')  # first line is data -> warning
# after
ds = TableDataset('data.tsv', headers=['text'])
Defensive patterns

Strategy: validation

Validate before calling

with open(path) as f:
    first = f.readline().rstrip('\n').split('\t')
if any(len(h) > 32 for h in first):
    pass_headers = first  # first line is data; pass headers explicitly

Type guard

def looks_like_headers(first_line_cells: List[str]) -> bool:
    return all(len(c) <= 32 and not c.strip().isdigit() for c in first_line_cells)

Prevention

When it happens

Trigger: Creating TableDataset (or subclasses like the AMR/table components) on a delimiter file whose first row contains long cells (>32 chars) and passing no headers= argument.

Common situations: Loading a headerless data file (e.g. raw sentences per line) where the first sample is treated as a header; delimiter mismatch making a whole row parse as one giant header cell.

Related errors


AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27). Data as JSON: /api/errors/5c8b2bbfe5830ba7. Report an issue: GitHub.