Skip to content

[Bug]: Enum accepts non-string categories #3338

@FBruzzesi

Description

@FBruzzesi

Describe the bug

In narwhals, Enum does accept non-string inputs but polars doesn't. Spotted in anyschema 🙏🏼

Steps or code to reproduce the bug

This is all good and well

import narwhals as nw

nw.Enum([True, False])
nw.Enum([1, 2])

But polars checks and raises:

import polars as pl

pl.Enum([True, False])
# TypeError: Enum categories must be strings; found data of type Boolean

pl.Enum([1, 2])
# TypeError: Enum categories must be strings; found data of type Int64

Same for a non-string enum

from enum import Enum
import polars as pl

class Number(Enum):
    ONE = 1
    TWO = 2
    THREE = 3

pl.Enum(Number)
# TypeError: Enum categories must be strings; found data of type Int64

Expected results

Raise an exception

Actual results

Passthrough

Please run narwhals.show_versions() and enter the output below.

System:
    python: 3.13.9 (main, Oct 14 2025, 13:52:31) [Clang 17.0.0 (clang-1700.0.13.3)]
   machine: macOS-15.7.1-arm64-arm-64bit-Mach-O

Python dependencies:
     narwhals: 2.12.0
       polars: 1.35.2

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions