Skip to content

fix test pandas error - #241

Merged
stefansc1 merged 1 commit into
devfrom
fix/pandas_view
Oct 15, 2026
Merged

stefansc1 merged 1 commit into
devfrom
fix/pandas_view

Conversation

@j-brendel

Copy link
Copy Markdown
Collaborator

Tests crash with AttributeError: 'Series' object has no attribute 'view'

Problem

Running pytest tests can fail with:

AttributeError: 'Series' object has no attribute 'view'

The traceback points into tests/test_consumption.py::TestConsumption::test_calculate_consumption:

consumption_df = pd.read_csv(self.consumption_path)
consumption_col = consumption_df["consumption_kwh_per_km"].view()
...
consumption_col[:] = true_cons(lol_col, incline_col, speed_col, temp_col)

pandas.Series.view() was deprecated in pandas 2.x and has been removed entirely in pandas 3.x
(installed here: pandas 3.0.5). The call was used to obtain a view of the DataFrame column that
could be mutated in place (consumption_col[:] = ...), so the new values end up back in
consumption_df without reassigning the column explicitly. consumption_col itself is never
used again after that line — the DataFrame is what gets passed on to
consumption_calculator.set_consumption_interpolation(...).

This is purely a test-environment issue (pandas version used in the local venv), not a bug in
simba/consumption.py itself.

Solution

Skip the view/in-place-mutation detour and assign the computed values straight to the column:

consumption_df = pd.read_csv(self.consumption_path)
lol_col = consumption_df["level_of_loading"]
incline_col = consumption_df["incline"]
speed_col = consumption_df["mean_speed_kmh"]
temp_col = consumption_df["t_amb"]

consumption_df["consumption_kwh_per_km"] = true_cons(
    lol_col, incline_col, speed_col, temp_col)
  • Functionally identical: consumption_df["consumption_kwh_per_km"] ends up holding the same
    values before being passed into set_consumption_interpolation.
  • Works regardless of pandas version, since it no longer depends on the removed .view() API.
  • No production code is affected; the fix is contained to the test file.

Implementation (branch fix/pandas_view)

  • tests/test_consumption.py: replaced .view() + in-place assignment with a direct column
    assignment in test_calculate_consumption.

@j-brendel
j-brendel requested a review from stefansc1 October 12, 2026 08:33

@stefansc1 stefansc1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also works in pandas 2.x

@stefansc1
stefansc1 merged commit 40175e2 into dev Oct 15, 2026
4 checks passed
@stefansc1
stefansc1 deleted the fix/pandas_view branch October 15, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants