[Bug]: Registering an empty AgentSet in Model.sets raises ColumnNotFoundError for "unique_id"

Abierto
#204 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

Start with AgentSetRegistry.add in mesa_frames/concrete/agentsetregistry.py, where agentset["unique_id"] is read around line 108, then check _recompute_ids and the empty pl.DataFrame() created in AgentSet.__init__. Reproduce with the snippet in the issue. Done means an empty set can be registered with zero agents, and index and pos work on it, with a regression test added. The maintainer has not yet chosen between restoring a typed empty column and handling its absence, so confirm the approach before writing code.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug triage
📝 Description

Adding an AgentSet that has no agents yet to model.sets (or an
AgentSetRegistry) raises polars ColumnNotFoundError: unable to find column
"unique_id".

This worked before PR #110 ("Generate automatically unique_id"). At that
point an empty AgentSet was created with a unique_id column in its schema.
After #110, an empty AgentSet has no columns, but AgentSetRegistry.add still
reads agentset["unique_id"].

The same missing column also makes _recompute_ids, AgentSet.index and
(when a space is set) AgentSet.pos fail on an empty set.

🔄 Steps to Reproduce
from mesa_frames import AgentSet, Model

class E(AgentSet):
    def step(self):
        pass

m = Model()
m.sets += E(m)
🎯 Expected Behavior

I expected the empty AgentSet to be registered with zero agents, so that a
set can be declared (for example in Model.init) and populated later. This
worked before #110.

🚨 Actual Behavior

polars.exceptions.ColumnNotFoundError: unable to find column "unique_id";
valid columns: []

🖥️ Python Version

3.13.2

Operating System

Windows 11 (build 10.0.26300)

Relevant Packages

polars 1.36.1
mesa 3.3.1
mesa-frames at main, commit ef92326

📊 Relevant Log Output
Traceback (most recent call last):
  File "<string>", line 5, in <module>
    m.sets += E(m)
  File "mesa_frames/abstract/agentsetregistry.py", line 480, in __iadd__
    return self.add(sets=other, inplace=True)
  File "mesa_frames/concrete/agentsetregistry.py", line 108, in add
    [obj._ids] + [pl.Series(agentset["unique_id"]) for agentset in other_list]
...
polars.exceptions.ColumnNotFoundError: unable to find column "unique_id"; valid columns: []
➕ Additional Context

Before commit e757571 (#110), AgentSet.init created the empty frame with
a unique_id column: pl.DataFrame(schema={"unique_id": pl.Int64}). After it,
it is pl.DataFrame() with no columns, but AgentSetRegistry.add (and
_recompute_ids) still read agentset["unique_id"].

The same missing column also makes AgentSet.index fail on an empty set, and
AgentSet.pos fail when a space is set.

I searched open and closed issues and PRs for "empty", "unique_id" and
"AgentSetRegistry" and did not find this reported.

Question: should empty sets be registrable? If so, would you prefer restoring
a typed empty unique_id column, or handling its absence where it is read? Or
is the current behaviour intended?

I'm happy to send a PR once you say which approach you prefer.

Lenguaje dominante
Python
Estrellas
44
Forks
20
Merge medio
1 min
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de mesa/mesa-frames

Todos los issues de mesa/mesa-frames

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.