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
- Pass headers=[...] explicitly so the first line is treated as data
- Verify self.delimiter matches the file's actual delimiter
- 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
- Always pass headers= for headerless files
- Match delimiter to the file format
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
- Chinese Treebank 9.0 is a copyright dataset owned by LDC whi
- Not supported.
- Not supported.
- Caching for the dataset is not enabled, try `dataset.purge_c
- The main dependency conflicts with 2nd dependency at ID={i},
AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27).
Data as JSON: /api/errors/5c8b2bbfe5830ba7.
Report an issue: GitHub.