Skip to content

detect_clearsky should use inferred window length when comparing to samples_per_window #2542

Closed

Description

@wholmgren

Describe the bug
detect_clearsky should use inferred window length when comparing to samples_per_window. Instead it uses the input window_length (default window_length=10). Relevant lines are linked below. Note that samples_per_window and the raise are before the if infer_limits block.

https://github.com/pvlib/pvlib-python/blob/39867da0c6d3738cf2d83f230961d59458c68e33/pvlib/clearsky.py#L818C1-L837C1

To Reproduce

import numpy as np
import pandas as pd

import pvlib

start = '2024-01-01'
end = '2025-01-01'
freq = '10min'
times = pd.date_range(start=start, end=end, freq=freq)
x1 = pd.Series(np.random.rand(len(times)), index=times)
x2 = pd.Series(np.random.rand(len(times)), index=times)

# works if we change window_length, even though it'll be overriden
pvlib.clearsky.detect_clearsky(x1, x2, infer_limits=True, window_length=30)

# fails
pvlib.clearsky.detect_clearsky(x1, x2, infer_limits=True)
$ python detect_clearsky_infer_bug.py 
Traceback (most recent call last):
  File "/home/wilhol/code/pvlib-python/detect_clearsky_infer_bug.py", line 17, in <module>
    pvlib.clearsky.detect_clearsky(x1, x2, infer_limits=True)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wilhol/code/pvlib-python/pvlib/clearsky.py", line 822, in detect_clearsky
    raise ValueError(f"Samples per window of {samples_per_window}"
    ...<3 lines>...
                     f" window length to {3*sample_interval} or longer.")
ValueError: Samples per window of 1 found. Each window must contain at least 3 data points. Window length of 10 found; increase window length to 30.0 or longer.

Expected behavior
samples_per_window and associated check should be calculated with respect to the inferred window length, if it exists.

Versions:

  • pvlib.__version__: 0.13.0

Additional context
#2281 introduced the sample window check in an effort to make an error less mysterious. I think it was simply inserted a little too early in the function.

Activity

  1. aledelaoo commented on Aug 30, 2025

    @aledelaoo

    I’m interested in working on this issue. Would you like to assign this issue to me, or should I just open a pull request once I have the fix and tests ready?

  2. echedey-ls commented on Aug 30, 2025

    @echedey-ls
    Member

    Hi @aledelaoo , thanks for showing interest in contributing to pvlib!

    Feel free to give it a shot. We don't use the assignment of issues feature (for now). If this is your first time contributing, I recommend you tackle an easier issue first (a typo, for example) and become familiar with the contributing guidelines. I don't know how proficient you are in Python, data analysis, nor open source. Should you find any trouble, please contact us at the mailing list: https://groups.google.com/g/pvlib-python

  3. added this to the v0.13.1 milestone on Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions