pola-rs/polars · error · TypeError

`path` argument has invalid type

Error message

`path` argument has invalid type {qualified_type_name(path)!r}, and cannot be turned into a sink target

What it means

_to_sink_target conversion fallback: the sink `path` argument must be a str/Path, file-like IO object, PartitionBy spec, or an object with a .write method; anything else falls to the guard naming the invalid type. E.g. passing an int fd or None.

Solutions

  1. Pass path as a string, Path, or supported file-like object that can be turned into a sink target.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at py-polars/src/polars/lazyframe/engine.py:63 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pola-rs/polars@68506541d2 (2026-08-28). Data as JSON: /api/errors/32059323ea044a46. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/lazyframe/engine.py:62


def _to_sink_target(
    path: str | Path | IO[bytes] | IO[str] | PartitionBy,
) -> str | Path | IO[bytes] | IO[str] | PartitionBy:
    from polars.io.partition import PartitionBy

    if isinstance(path, (str, Path)):
        return normalize_filepath(path)
    elif isinstance(path, io.IOBase):
        return path
    elif isinstance(path, PartitionBy):
        return path
    elif callable(getattr(path, "write", None)):
        # This allows for custom writers
        return path
    else:
        msg = f"`path` argument has invalid type {qualified_type_name(path)!r}, and cannot be turned into a sink target"
        raise TypeError(msg)


class Engine(ABC):
    """
    Base class for query execution engines.

    Subclass this to plug a new backend into Polars.

    .. warning::
        This functionality is considered **unstable**. It may be changed
        at any point without it being considered a breaking change.
    """

    @property
    @abstractmethod
    def name(self) -> str:
        """Engine identifier."""

View on GitHub (pinned to 68506541d2)