Skip to content

Commit

Permalink
fix: AgentSetDF.shuffle should use a seed generated from the object r…
Browse files Browse the repository at this point in the history
…andom generator
  • Loading branch information
adamamer20 committed Sep 20, 2024
1 parent d026c9b commit 04714fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion mesa_frames/concrete/pandas/agentset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def step(self):
from collections.abc import Callable, Collection, Iterable, Iterator, Sequence
from typing import TYPE_CHECKING

import numpy as np
import pandas as pd
import polars as pl
from typing_extensions import Any, Self, overload
Expand Down Expand Up @@ -237,7 +238,9 @@ def select( # noqa : D102

def shuffle(self, inplace: bool = True) -> Self: # noqa : D102
obj = self._get_obj(inplace)
obj._agents = obj._agents.sample(frac=1)
obj._agents = obj._agents.sample(
frac=1, random_state=obj.random.integers(np.iinfo(np.int32).max)
)
return obj

def sort( # noqa : D102
Expand Down
8 changes: 7 additions & 1 deletion mesa_frames/concrete/polars/agentset.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def step(self):
from mesa_frames.concrete.model import ModelDF
from mesa_frames.concrete.pandas.agentset import AgentSetPandas

import numpy as np


@copydoc(AgentSetDF)
class AgentSetPolars(AgentSetDF, PolarsMixin):
Expand Down Expand Up @@ -255,7 +257,11 @@ def select(

def shuffle(self, inplace: bool = True) -> Self:
obj = self._get_obj(inplace)
obj._agents = obj._agents.sample(fraction=1, shuffle=True)
obj._agents = obj._agents.sample(
fraction=1,
shuffle=True,
seed=obj.random.integers(np.iinfo(np.int32).max),
)
return obj

def sort(
Expand Down

0 comments on commit 04714fa

Please sign in to comment.