{"record":{"id":"592858b71b088e04","repo":"matplotlib/matplotlib","slug":"s-r-is-not-a-valid-cycler-construction-e","errorCode":null,"errorMessage":"{s!r} is not a valid cycler construction: {e}","messagePattern":"(.+?) is not a valid cycler construction: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/rcsetup.py","lineNumber":927,"sourceCode":"            loc = ast.literal_eval(loc)\n        except (SyntaxError, ValueError):\n            pass\n    if isinstance(loc, int):\n        if 0 <= loc <= 10:\n            return loc\n    if isinstance(loc, tuple):\n        if len(loc) == 2 and all(isinstance(e, Real) for e in loc):\n            return loc\n    raise ValueError(f\"{loc} is not a valid legend location.\")\n\n\ndef validate_cycler(s):\n    \"\"\"Return a Cycler object from a string repr or the object itself.\"\"\"\n    if isinstance(s, str):\n        try:\n            s = _parse_cycler_string(s)\n        except Exception as e:\n            raise ValueError(f\"{s!r} is not a valid cycler construction: {e}\"\n                             ) from e\n    if isinstance(s, Cycler):\n        cycler_inst = s\n    else:\n        raise ValueError(f\"Object is not a string or Cycler instance: {s!r}\")\n\n    unknowns = cycler_inst.keys - (set(_prop_validators) | set(_prop_aliases))\n    if unknowns:\n        raise ValueError(\"Unknown artist properties: %s\" % unknowns)\n\n    # Not a full validation, but it'll at least normalize property names\n    # A fuller validation would require v0.10 of cycler.\n    checker = set()\n    for prop in cycler_inst.keys:\n        norm_prop = _prop_aliases.get(prop, prop)\n        if norm_prop != prop and norm_prop in cycler_inst.keys:\n            raise ValueError(f\"Cannot specify both {norm_prop!r} and alias \"\n                             f\"{prop!r} in the same prop_cycle\")","sourceCodeStart":909,"sourceCodeEnd":945,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/rcsetup.py#L909-L945","documentation":"validate_cycler() (lib/matplotlib/rcsetup.py:927) is the rcParams validator for axes.prop_cycle. When given a string it calls _parse_cycler_string(); any exception raised while parsing or evaluating (syntax error, unsupported operator, non-cycler() call, non-literal leaf) is caught and re-raised as ValueError with this wrapper message, chaining the original cause via 'from e'.","triggerScenarios":"rcParams['axes.prop_cycle'] = 'cycler(linestyle=[\"-\", \"--\"]' (unbalanced); 'cycler(color=colors)' (name not literal); 'cycler(c=\"rgb\") - cycler(...)' (unsupported operator); any .mplstyle axes.prop_cycle line that fails any inner rule of the safe parser.","commonSituations":"Loading third-party or hand-edited style sheets with subtly broken cycler strings; upgrading matplotlib versions that replaced eval with the restricted parser so previously 'working' creative strings now fail; composing prop_cycle strings with f-strings.","solutions":["Read the chained cause (__cause__) — it names the exact inner problem; fix that first","Simplify the string to plain cycler(...) calls with literal lists joined by +","Skip strings entirely: assign the Cycler object built in code","Validate style files at startup with matplotlib.style.use after a dry-run rcParams assignment so failures surface early"],"exampleFix":"# before\nmpl.rcParams['axes.prop_cycle'] = \"cycler(lw=[1, 2]\"  # missing closing paren\n# after\nmpl.rcParams['axes.prop_cycle'] = \"cycler(lw=[1, 2])\"","handlingStrategy":"try-catch","validationCode":"from matplotlib.rcsetup import validate_cycler\ntry:\n    validate_cycler(prop_cycle_string)\nexcept ValueError as e:\n    raise ValueError(f'style file prop_cycle broken: {e}') from e","typeGuard":"def is_parseable_cycler_string(s):\n    from matplotlib.rcsetup import validate_cycler\n    try:\n        validate_cycler(s)\n        return True\n    except ValueError:\n        return False","tryCatchPattern":"try:\n    mpl.rcParams['axes.prop_cycle'] = s\nexcept ValueError as e:\n    if 'is not a valid cycler construction' in str(e):\n        mpl.rcParams['axes.prop_cycle'] = cycler(color=plt.rcParams['axes.prop_cycle'].by_key().get('color', ['b']))\n    else:\n        raise","preventionTips":["Inspect e.__cause__ — it carries the exact inner failure","Dry-run style files through validate_cycler at load time","Generate strings with repr(cycler(...)) rather than by hand"],"tags":["matplotlib","rcsetup","cycler","prop-cycle","validation"],"backgroundTag":"invalid-prop-cycle-string","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}