Repository navigation
fix test pandas error - #241
Merged
Merged
Conversation
stefansc1
approved these changes
Oct 15, 2026
stefansc1
left a comment
Collaborator
There was a problem hiding this comment.
Also works in pandas 2.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tests crash with
AttributeError: 'Series' object has no attribute 'view'Problem
Running
pytest testscan fail with:The traceback points into
tests/test_consumption.py::TestConsumption::test_calculate_consumption: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 inconsumption_dfwithout reassigning the column explicitly.consumption_colitself is neverused 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.pyitself.Solution
Skip the view/in-place-mutation detour and assign the computed values straight to the column:
consumption_df["consumption_kwh_per_km"]ends up holding the samevalues before being passed into
set_consumption_interpolation..view()API.Implementation (branch
fix/pandas_view)tests/test_consumption.py: replaced.view()+ in-place assignment with a direct columnassignment in
test_calculate_consumption.