{"record":{"id":"c95b9425b4f451df","repo":"pola-rs/polars","slug":"invalid-config-string-did-you-mean-to-use-load-f","errorCode":null,"errorMessage":"invalid Config string (did you mean to use `load_from_file`?)","messagePattern":"invalid Config string \\(did you mean to use `load_from_file`\\?\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/config.py","lineNumber":408,"sourceCode":"    def load(cls, cfg: str) -> Config:\n        \"\"\"\n        Load (and set) previously saved Config options from a JSON string.\n\n        Parameters\n        ----------\n        cfg : str\n            JSON string produced by `Config.save()`.\n\n        See Also\n        --------\n        load_from_file : Load (and set) Config options from a JSON file.\n        save : Save the current set of Config options as a JSON string or file.\n        \"\"\"\n        try:\n            options = json.loads(cfg)\n        except json.JSONDecodeError as err:\n            msg = \"invalid Config string (did you mean to use `load_from_file`?)\"\n            raise ValueError(msg) from err\n\n        cfg_load = Config()\n        opts = options.get(\"environment\", {})\n        if \"POLARS_ENGINE_AFFINITY\" in opts:\n            # A saved affinity value replaces any object affinity.\n            set_engine_affinity_override(None)\n        for key, opt in opts.items():\n            if opt is None:\n                os.environ.pop(key, None)\n            else:\n                os.environ[key] = opt\n\n        for cfg_methodname, value in options.get(\"direct\", {}).items():\n            if hasattr(cfg_load, cfg_methodname):\n                getattr(cfg_load, cfg_methodname)(value)\n\n        plr.config_reload_env_vars()\n        return cfg_load","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/config.py#L390-L426","documentation":"Raised by Config.load when the given string is not valid JSON. Since load expects the JSON string produced by Config.save(), a JSONDecodeError usually means the user passed a file path instead of file contents.","triggerScenarios":"Calling Config.load('/path/to/config.json') (a path, not a JSON string) or passing any non-JSON string.","commonSituations":"Confusing Config.load (string) with Config.load_from_file (path); passing a dict/serialized YAML instead of the polars JSON format.","solutions":["Use Config.load_from_file(path) when you have a file path","Pass the exact JSON string returned by Config.save()","Validate the string parses as JSON before calling load"],"exampleFix":"// before\npl.Config.load('~/.polars_cfg.json')  # ValueError\n// after\npl.Config.load_from_file('~/.polars_cfg.json')","handlingStrategy":"try-catch","validationCode":"import json\ntry:\n    json.loads(cfg)\nexcept json.JSONDecodeError:\n    raise ValueError('config string is not JSON; use load_from_file for paths')","typeGuard":"def is_json(s: str) -> bool:\n    try:\n        json.loads(s)\n        return True\n    except json.JSONDecodeError:\n        return False","tryCatchPattern":"try:\n    pl.Config.load(cfg)\nexcept ValueError:\n    # maybe a path was passed\n    pl.Config.load_from_file(cfg)","preventionTips":["Remember load() takes a JSON string, load_from_file() a path","Only pass output of Config.save() to load","Sanity-check with json.loads first"],"tags":["polars","config","json"],"backgroundTag":"json-parse-error","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}