Skip to content

memilio.simulation incompatible with pandas 3 #1483

@kilianvolmer

Description

@kilianvolmer

Bug description

When running the memilio.simulation unittests with pandas3.0, I get four parallel errors like this one:

======================================================================
ERROR: test_compare_with_cpp (test_osecir.Test_osecir_integration.test_compare_with_cpp)
Tests the correctness of the python bindings. The results of a simulation
----------------------------------------------------------------------
Traceback (most recent call last):
  File ".../.venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 3641, in get_loc
    return self._engine.get_loc(casted_key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pandas/_libs/index.pyx", line 168, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 578, in pandas._libs.index.StringObjectEngine._check_type
KeyError: 1

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File ".../pycode/memilio-simulation/tests/test_osecir.py", line 149, in test_compare_with_cpp
    timestep[index_compartment + 1],
    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/pandas/core/series.py", line 959, in __getitem__
    return self._get_value(key)
           ^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/pandas/core/series.py", line 1046, in _get_value
    loc = self.index.get_loc(label)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 3648, in get_loc
    raise KeyError(key) from err
KeyError: 1


When using pandas 2.3.3, I get the corresponding deprecation warnings:

.............................../.../pycode/memilio-simulation/tests/test_osecir.py:149: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`

Version

Linux

To reproduce

Run the memilio.simulation unittests using pandas 3.

Relevant log output

Add any relevant information, e.g. used compiler, screenshots.

Checklist

  • Attached labels, especially loc:: or model:: labels.
  • Linked to project

Metadata

Metadata

Assignees

No one assigned

    Labels

    class::bugBugs found in the softwareloc::python interfaceThis issue concerns the python interface to the backend implementation.prio::highThe priority of this task is high.

    Type

    Projects

    Status

    🏗 Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions