Description
In the Elexon forecast data processing pipeline, assignment to start_time is performed on a DataFrame slice, which raises a pandas SettingWithCopyWarning.
This warning occurs when a transformation is applied to a view rather than a standalone DataFrame, which may lead to unpredictable behavior.
Expected Behavior
- No
SettingWithCopyWarning should be emitted during Elexon preprocessing tests.
- Column assignments should operate on a safe DataFrame copy or use
.loc.
Actual Behavior
SettingWithCopyWarning is raised when assigning to start_time.
Scope
Suggested Fix
Avoid chained assignment by explicitly creating a copy of the DataFrame or using .loc before mutating columns.
Example approaches:
df = df.copy()
df["start_time"] = ...
or
df.loc[:, "start_time"] = ...
Validation
Run the following test to confirm the warning is resolved:
python -m pytest tests/test_elexon_plot.py -q
Verify:
- Tests pass successfully
SettingWithCopyWarning no longer appears
Description
In the Elexon forecast data processing pipeline, assignment to
start_timeis performed on a DataFrame slice, which raises a pandasSettingWithCopyWarning.This warning occurs when a transformation is applied to a view rather than a standalone DataFrame, which may lead to unpredictable behavior.
Expected Behavior
SettingWithCopyWarningshould be emitted during Elexon preprocessing tests..loc.Actual Behavior
SettingWithCopyWarningis raised when assigning tostart_time.Scope
elexon_plots.pyonly.Suggested Fix
Avoid chained assignment by explicitly creating a copy of the DataFrame or using
.locbefore mutating columns.Example approaches:
or
Validation
Run the following test to confirm the warning is resolved:
Verify:
SettingWithCopyWarningno longer appears