pola-rs/polars · error · ValueError

invalid profile name

Error message

invalid profile name {profile_name!r}; expected one of {valid_profile_names!r}

What it means

set_profile validates the profile name against the Literal type ParametricProfileNames (fetched via typing.get_args). Unknown names raise ValueError before setting the POLARS_HYPOTHESIS_PROFILE environment variable.

Solutions

  1. Use a valid name; the error lists them (e.g. check get_args(ParametricProfileNames) or current docs).
  2. Fix typos in the profile string.
  3. If driven by config, validate against get_args(ParametricProfileNames) before calling.

Example fix

# before
set_profile('fast')  # invalid if not in current Literal

# after
set_profile('low')  # one of the valid profile names
Defensive patterns

Strategy: validation

Validate before calling

from typing import get_args
from polars.testing.parametric.profiles import ParametricProfileNames
if profile_name not in get_args(ParametricProfileNames):
    raise ValueError(f"bad profile {profile_name!r}")
set_profile(profile_name)

Try / catch

try:
    set_profile(name)
except ValueError as e:
    print(e)  # lists valid names
    set_profile('default')

Prevention

When it happens

Trigger: set_profile('fast') misspelled, or using a legacy/removed profile name from older polars versions; loading profiles from config with stale names via load_profile.

Common situations: Copying example code from an old blog post after profiles were renamed; typos like 'deafult'; constructing profile names dynamically from user config.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/0862f7cd6c7421da. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/testing/parametric/profiles.py:105

        a custom profile with that value).

    Examples
    --------
    >>> # prefer the 'balanced' profile for running parametric tests
    >>> from polars.testing.parametric import set_profile
    >>> set_profile("balanced")
    """
    profile_name = str(profile).split(".")[-1]
    if profile_name.replace("_", "").isdigit():
        profile_name = str(int(profile_name))

    else:
        from typing import get_args

        valid_profile_names = get_args(ParametricProfileNames)
        if profile_name not in valid_profile_names:
            msg = f"invalid profile name {profile_name!r}; expected one of {valid_profile_names!r}"
            raise ValueError(msg)

    os.environ["POLARS_HYPOTHESIS_PROFILE"] = profile_name

View on GitHub (pinned to fe841f959e)