{"record":{"id":"5c8b2bbfe5830ba7","repo":"hankcs/HanLP","slug":"as-you-did-not-pass-in-headers-to-tabledataset","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"hanlp/common/dataset.py","lineNumber":836,"sourceCode":"class TableDataset(TransformableDataset):\n    def __init__(self,\n                 data: Union[str, List],\n                 transform: Union[Callable, List] = None,\n                 cache=None,\n                 delimiter='auto',\n                 strip=True,\n                 headers=None) -> None:\n        self.headers = headers\n        self.strip = strip\n        self.delimiter = delimiter\n        super().__init__(data, transform, cache)\n\n    def load_file(self, filepath: str):\n        for idx, cells in enumerate(read_cells(filepath, strip=self.strip, delimiter=self.delimiter)):\n            if not idx and not self.headers:\n                self.headers = cells\n                if any(len(h) > 32 for h in self.headers):\n                    warnings.warn('As you did not pass in `headers` to `TableDataset`, the first line is regarded as '\n                                  'headers. However, the length for some headers are too long (>32), which might be '\n                                  'wrong. To make sure, pass `headers=...` explicitly.')\n            else:\n                yield dict(zip(self.headers, cells))\n","sourceCodeStart":818,"sourceCodeEnd":841,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/dataset.py#L818-L841","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nds = TableDataset('data.tsv')  # first line is data -> warning\n# after\nds = TableDataset('data.tsv', headers=['text'])","handlingStrategy":"validation","validationCode":"with open(path) as f:\n    first = f.readline().rstrip('\\n').split('\\t')\nif any(len(h) > 32 for h in first):\n    pass_headers = first  # first line is data; pass headers explicitly","typeGuard":"def looks_like_headers(first_line_cells: List[str]) -> bool:\n    return all(len(c) <= 32 and not c.strip().isdigit() for c in first_line_cells)","tryCatchPattern":null,"preventionTips":["Always pass headers= for headerless files","Match delimiter to the file format"],"tags":["dataset","csv","headers"],"backgroundTag":"header-detection-warning","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}