Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify stacklevel in calls to warnings.warn #327

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 57 additions & 37 deletions docs/TrendAnalysis_example_pvdaq4.ipynb

Large diffs are not rendered by default.

80 changes: 49 additions & 31 deletions docs/degradation_and_soiling_example.ipynb

Large diffs are not rendered by default.

82 changes: 48 additions & 34 deletions docs/degradation_and_soiling_example_pvdaq_4.ipynb

Large diffs are not rendered by default.

34 changes: 20 additions & 14 deletions docs/system_availability_example.ipynb

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions rdtools/analysis_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ def _pvwatts_norm(self, poa_global, temperature_cell):

if self.gamma_pdc is None:
warnings.warn('Temperature coefficient not passed in to TrendAnalysis'
'. No temperature correction will be conducted.')
'. No temperature correction will be conducted.',
stacklevel=3)
pvwatts_kws = {"poa_global": poa_global,
"power_dc_rated": power_dc_rated,
"temperature_cell": temperature_cell,
Expand Down Expand Up @@ -455,13 +456,15 @@ def _filter(self, energy_normalized, case):
ad_hoc_filter = self.filter_params['ad_hoc_filter']

if ad_hoc_filter.isnull().any():
warnings.warn('ad_hoc_filter contains NaN values; setting to False (excluding)')
warnings.warn('ad_hoc_filter contains NaN values; setting to False (excluding)',
stacklevel=3)
ad_hoc_filter = ad_hoc_filter.fillna(False)

if not filter_components.index.equals(ad_hoc_filter.index):
warnings.warn('ad_hoc_filter index does not match index of other filters; missing '
'values will be set to True (kept). Align the index with the index '
'of the filter_components attribute to prevent this warning')
'of the filter_components attribute to prevent this warning',
stacklevel=3)
ad_hoc_filter = ad_hoc_filter.reindex(filter_components.index).fillna(True)

filter_components['ad_hoc_filter'] = ad_hoc_filter
Expand Down
4 changes: 2 additions & 2 deletions rdtools/availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
warnings.warn(
'The availability module is currently experimental. The API, results, '
'and default behaviors may change in future releases (including MINOR '
'and PATCH releases) as the code matures.'
'and PATCH releases) as the code matures.', stacklevel=2
)


Expand Down Expand Up @@ -537,7 +537,7 @@ def _combine_losses(self, rollup_period='M'):
'levels. This is unexpected and could indicate a problem with '
'the input time series data.'
)
warnings.warn(msg, UserWarning)
warnings.warn(msg, UserWarning, stacklevel=3)

self.loss_total = self.loss_system + self.loss_subsystem

Expand Down
6 changes: 4 additions & 2 deletions rdtools/clearsky_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def get_clearsky_tamb(times, latitude, longitude, window_size=40,
if freq_actual is None:
freq_actual = pd.infer_freq(times[:10])
warnings.warn("Input 'times' has no frequency attribute. "
"Inferring frequency from first 10 timestamps.")
"Inferring frequency from first 10 timestamps.",
stacklevel=2)
else:
freq_actual = times.freq

Expand Down Expand Up @@ -115,7 +116,8 @@ def solar_noon_offset(utc_offset):
df['solar_noon_offset'].values)
if df['Clear Sky Temperature (C)'].isna().any():
warnings.warn("Clear Sky Temperature includes NaNs, "
"possibly invalid Lat/Lon coordinates.", UserWarning)
"possibly invalid Lat/Lon coordinates.", UserWarning,
stacklevel=2)
return df['Clear Sky Temperature (C)']


Expand Down
15 changes: 10 additions & 5 deletions rdtools/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def clip_filter(power_ac, model="quantile", **kwargs):
"parameters have been interpreted as model= "
f"'quantile_clip_filter', quantile={quantile}. "
"This syntax will be removed in a future version.",
rdtools._deprecation.rdtoolsDeprecationWarning)
rdtools._deprecation.rdtoolsDeprecationWarning,
stacklevel=2)
kwargs['quantile'] = quantile
model = 'quantile'

Expand Down Expand Up @@ -232,7 +233,8 @@ def _format_clipping_time_series(power_ac, mounting_type):
if not has_timezone.all():
warnings.warn("Function expects timestamps in local time. "
"For best results pass a time-zone-localized "
"time series localized to the correct local time zone.")
"time series localized to the correct local time zone.",
stacklevel=3)
# Check the other input variables to ensure that they are the
# correct format
if (mounting_type != "single_axis_tracking") & (mounting_type != "fixed"):
Expand Down Expand Up @@ -285,7 +287,8 @@ def _check_data_sampling_frequency(power_ac):
warnings.warn("Variable sampling frequency across time series. "
"Less than 95% of the time series is sampled at the "
"same interval. This function was not tested "
"on variable frequency data--use at your own risk!")
"on variable frequency data--use at your own risk!",
stacklevel=3)
return


Expand Down Expand Up @@ -416,7 +419,8 @@ def logic_clip_filter(power_ac,
warnings.warn("The logic-based filter is an experimental clipping filter "
"that is still under development. The API, results, and "
"default behaviors may change in future releases (including "
"MINOR and PATCH). Use at your own risk!")
"MINOR and PATCH). Use at your own risk!",
stacklevel=2)
# Format the time series
power_ac, index_name = _format_clipping_time_series(power_ac,
mounting_type)
Expand Down Expand Up @@ -641,7 +645,8 @@ def xgboost_clip_filter(power_ac,
warnings.warn("The XGBoost filter is an experimental clipping filter "
"that is still under development. The API, results, and "
"default behaviors may change in future releases (including "
"MINOR and PATCH). Use at your own risk!")
"MINOR and PATCH). Use at your own risk!",
stacklevel=2)
# Load in the XGBoost model
xgboost_clipping_model = _load_xgboost_clipping_model()
# Format the power or energy time series
Expand Down
2 changes: 1 addition & 1 deletion rdtools/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def _interpolate_series(time_series, target_index, max_timedelta=None,
warnings.warn("Fraction of excluded data "
f"({100*fraction_excluded:0.02f}%) "
"exceeded threshold",
UserWarning)
UserWarning, stacklevel=3)

# put data on index that includes both original and target indicies
target_timestamps = pd.Index(target_index.view('int64'))
Expand Down
8 changes: 4 additions & 4 deletions rdtools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def soiling_monte_carlo_plot(soiling_info, normalized_yield, point_alpha=0.5,
warnings.warn(
'The soiling module is currently experimental. The API, results, '
'and default behaviors may change in future releases (including MINOR '
'and PATCH releases) as the code matures.'
'and PATCH releases) as the code matures.', stacklevel=2
)

fig, ax = plt.subplots()
Expand Down Expand Up @@ -225,7 +225,7 @@ def soiling_interval_plot(soiling_info, normalized_yield, point_alpha=0.5,
warnings.warn(
'The soiling module is currently experimental. The API, results, '
'and default behaviors may change in future releases (including MINOR '
'and PATCH releases) as the code matures.'
'and PATCH releases) as the code matures.', stacklevel=2
)

sratio = soiling_info['soiling_ratio_perfect_clean']
Expand Down Expand Up @@ -265,7 +265,7 @@ def soiling_rate_histogram(soiling_info, bins=None):
warnings.warn(
'The soiling module is currently experimental. The API, results, '
'and default behaviors may change in future releases (including MINOR '
'and PATCH releases) as the code matures.'
'and PATCH releases) as the code matures.', stacklevel=2
)

soiling_summary = soiling_info['soiling_interval_summary']
Expand Down Expand Up @@ -385,7 +385,7 @@ def availability_summary_plots(power_system, power_subsystem, loss_total,
warnings.warn(
'The availability module is currently experimental. The API, results, '
'and default behaviors may change in future releases (including MINOR '
'and PATCH releases) as the code matures.'
'and PATCH releases) as the code matures.', stacklevel=2
)

fig = plt.figure(figsize=(16, 8))
Expand Down
12 changes: 7 additions & 5 deletions rdtools/soiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
warnings.warn(
'The soiling module is currently experimental. The API, results, '
'and default behaviors may change in future releases (including MINOR '
'and PATCH releases) as the code matures.'
'and PATCH releases) as the code matures.', stacklevel=2
)


Expand Down Expand Up @@ -110,7 +110,8 @@ def _calc_daily_df(self, day_scale=13, clean_threshold='infer',
warnings.warn('An even value of day_scale was passed. An odd value is '
'recommended, otherwise, consecutive days may be erroneously '
'flagged as cleaning events. '
'See https://github.com/NREL/rdtools/issues/189')
'See https://github.com/NREL/rdtools/issues/189',
stacklevel=2)

df = self.pm.to_frame()
df.columns = ['pi']
Expand Down Expand Up @@ -369,8 +370,8 @@ def _calc_monte(self, monte, method='half_norm_clean'):
'validity criteria such as increasing "max_relative_slope_error" '
'and/or "max_negative_step" and/or decreasing "min_interval_length".'
' Alternatively, consider using method="perfect_clean". For more'
' info see https://github.com/NREL/rdtools/issues/272'
)
' info see https://github.com/NREL/rdtools/issues/272',
stacklevel=3)
monte_losses = []
random_profiles = []
for _ in range(monte):
Expand Down Expand Up @@ -891,7 +892,8 @@ def annual_soiling_ratios(stochastic_soiling_profiles,
'The indexes of stochastic_soiling_profiles are not entirely '
'contained within the index of insolation_daily. Every day in '
'stochastic_soiling_profiles should be represented in '
'insolation_daily. This may cause erroneous results.')
'insolation_daily. This may cause erroneous results.',
stacklevel=2)

insolation_daily = insolation_daily.reindex(all_profiles.index)

Expand Down