marimo icon indicating copy to clipboard operation
marimo copied to clipboard

`AttributeError` when using `Enum` in pandas data frame

Open shunichironomura opened this issue 1 month ago • 1 comments

Describe the bug

If I use an enum as a value in a pandas data frame (see the Code to reproduce section for the code), the backend raises the following AttributeError in the console:

Exception in callback ConnectionDistributor._on_change()
handle: <Handle ConnectionDistributor._on_change()>
Traceback (most recent call last):
  File "/Users/nomura/Library/Application Support/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/asyncio/events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nomura/Library/Caches/uv/archive-v0/IwkhYu3lLq3liGhC68_Qc/lib/python3.13/site-packages/marimo/_utils/distributor.py", line 61, in _on_change
    response = self.input_connection.recv()
  File "/Users/nomura/Library/Application Support/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/multiprocessing/connection.py", line 251, in recv
    return _ForkingPickler.loads(buf.getbuffer())
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
AttributeError: Can't get attribute 'E' on <module '__main__' from '/Users/nomura/Library/Caches/uv/archive-v0/IwkhYu3lLq3liGhC68_Qc/bin/marimo'>

I don't see any error in the frontend, and the cell output is correct.

The code in the cell should be correct, as it doesn't raises any error when run as a plain Python script.

I don't see this as critical because the computation is correctly done and it's easy not to use enum values inside a data frame, but I'm reporting this in case it's not an intended behavior.

Environment

{
  "marimo": "0.10.13",
  "OS": "Darwin",
  "OS Version": "24.2.0",
  "Processor": "arm",
  "Python Version": "3.13.0",
  "Binaries": {
    "Browser": "--",
    "Node": "v20.17.0"
  },
  "Dependencies": {
    "click": "8.1.8",
    "docutils": "0.21.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.7",
    "narwhals": "1.22.0",
    "packaging": "24.2",
    "psutil": "6.1.1",
    "pygments": "2.19.1",
    "pymdown-extensions": "10.14",
    "pyyaml": "6.0.2",
    "ruff": "0.9.1",
    "starlette": "0.45.2",
    "tomlkit": "0.13.2",
    "typing-extensions": "missing",
    "uvicorn": "0.34.0",
    "websockets": "14.1"
  },
  "Optional Dependencies": {}
}

Code to reproduce

This marimo notebook raises the AttributeError when I run it with uv run marimo edit --sandbox notebook.py:

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "pandas==2.2.3",
# ]
# ///

import marimo

__generated_with = "0.10.13"
app = marimo.App(width="medium")


@app.cell
def _():
    from enum import Enum, auto
    import pandas as pd

    class E(Enum):
        A = auto()
        B = auto()

    df = pd.DataFrame([{"e": E.A}, {"e": E.B}])
    df
    return E, Enum, auto, df, pd


if __name__ == "__main__":
    app.run()

The following Python script with the same code as the notebook doesn't raise any error when I run it with uv run script.py:

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "pandas==2.2.3",
# ]
# ///
from enum import Enum, auto
import pandas as pd

class E(Enum):
    A = auto()
    B = auto()

df = pd.DataFrame([{"e": E.A}, {"e": E.B}])
print(df)

shunichironomura avatar Jan 15 '25 02:01 shunichironomura