{"record":{"id":"33d3de5e4b13b346","repo":"pandas-dev/pandas","slug":"cannot-override-builtin-dialect","errorCode":null,"errorMessage":"Cannot override builtin dialect.","messagePattern":"Cannot override builtin dialect\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/_testing/contexts.py","lineNumber":122,"sourceCode":"    name : str\n        The name of the dialect.\n    kwargs : mapping\n        The parameters for the dialect.\n\n    Raises\n    ------\n    ValueError : the name of the dialect conflicts with a builtin one.\n\n    See Also\n    --------\n    csv : Python's CSV library.\n    \"\"\"\n    import csv\n\n    _BUILTIN_DIALECTS = {\"excel\", \"excel-tab\", \"unix\"}\n\n    if name in _BUILTIN_DIALECTS:\n        raise ValueError(\"Cannot override builtin dialect.\")\n\n    csv.register_dialect(name, **kwargs)\n    try:\n        yield\n    finally:\n        csv.unregister_dialect(name)\n\n\ndef raises_chained_assignment_error(\n    extra_warnings: tuple[type[Warning], ...] = (),\n    extra_match: tuple[str | None, ...] = (),\n) -> AbstractContextManager:\n    from pandas._testing import assert_produces_warning\n\n    if CHAINED_WARNING_DISABLED:\n        if not extra_warnings:\n            from contextlib import nullcontext\n","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/_testing/contexts.py#L104-L140","documentation":"Raised by the `with_csv_dialect` context manager (in pandas._testing.contexts) when the requested dialect name collides with one of Python's csv builtin dialects: `excel`, `excel-tab`, or `unix`. The guard prevents tests from clobbering globally registered builtin dialects, which would leak across the test suite and corrupt other tests' CSV parsing.","triggerScenarios":"Calling `with with_csv_dialect('excel', delimiter=';'):` in a test; parameterizing a test over dialect names that include one of the three builtins.","commonSituations":"Writing a test that wants to define a custom CSV dialect and accidentally reusing a builtin name; copy-paste of dialect names between test files.","solutions":["Choose a non-builtin dialect name (e.g. 'excel-semicolon', 'test-custom').","If you must vary a builtin's behavior, register under a unique name and reference that.","Add a guard in test parametrization to skip builtin names."],"exampleFix":"// before\nwith with_csv_dialect('excel', delimiter=';'):\n    ...\n\n// after\nwith with_csv_dialect('excel-semicolon', delimiter=';'):\n    ...","handlingStrategy":"validation","validationCode":"_BUILTIN = {'excel', 'excel-tab', 'unix'}\nassert name not in _BUILTIN, f'{name} is a builtin csv dialect'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefix custom test dialect names with 'test-' or a project tag.","Avoid parameterizing tests over the three builtin dialect names."],"tags":["testing","csv","naming-conflict"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}