Closed
Description
Describe the bug
calling pvlib.losses.soiling_hsu(read_tmy3(<tmy file>, coerce_year=<year>), ...)
raises ValueError: index must be monotonic
because the last hour of a TMY3 file has been coerced to the same year as the first index, instead of the first hour of the next year
To Reproduce
Steps to reproduce the behavior:
from pvlib.losses import soiling_hsu
from pvlib.iotools import read_tmy3
from pvlib.tests.conftest import DATA_DIR
greensboro = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990)
greensboro_rain = greensboro[0].Lprecipdepth
soiling_hsu(greensboro_rain, cleaning_threshold=6, tilt=10, pm2_5=1e-5, pm10=1e-5)
raises ValueError: index must be monotonic
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-95-ff36a88e4e3a> in <module>
----> 1 soiling_hsu(greensboro_rain, cleaning_threshold=6, tilt=10, pm2_5=1e-5, pm10=1e-5)
~\Projects\pvlib-python\pvlib\losses.py in soiling_hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10, depo_veloc, rain_accum_period)
67
68 # accumulate rainfall into periods for comparison with threshold
---> 69 accum_rain = rainfall.rolling(rain_accum_period, closed='right').sum()
70 # cleaning is True for intervals with rainfall greater than threshold
71 cleaning_times = accum_rain.index[accum_rain >= cleaning_threshold]
~\projects\pvlib-python\venv\lib\site-packages\pandas\core\generic.py in rolling(self, window, min_periods, center, win_type, on, axis, closed)
10145 min_periods=min_periods,
10146 center=center, win_type=win_type,
> 10147 on=on, axis=axis, closed=closed)
10148
10149 cls.rolling = rolling
~\projects\pvlib-python\venv\lib\site-packages\pandas\core\window.py in rolling(obj, win_type, **kwds)
2624 return Window(obj, win_type=win_type, **kwds)
2625
-> 2626 return Rolling(obj, **kwds)
2627
2628
~\projects\pvlib-python\venv\lib\site-packages\pandas\core\window.py in __init__(self, obj, window, min_periods, center, win_type, axis, on, closed, **kwargs)
63 self.win_freq = None
64 self.axis = obj._get_axis_number(axis) if axis is not None else None
---> 65 self.validate()
66
67 @property
~\projects\pvlib-python\venv\lib\site-packages\pandas\core\window.py in validate(self)
1576 timedelta))):
1577
-> 1578 self._validate_monotonic()
1579 freq = self._validate_freq()
1580
~\projects\pvlib-python\venv\lib\site-packages\pandas\core\window.py in _validate_monotonic(self)
1610 formatted = self.on or 'index'
1611 raise ValueError("{0} must be "
-> 1612 "monotonic".format(formatted))
1613
1614 def _validate_freq(self):
I'm not sure, I guess I would expect it to be able to handle TMY3 data, but maybe it's the TMY3 with the year coerced to the same number that's the problem? This would also fail TMY3 if you didn't coerce the year, but it might fail silently in some weird ugly way that you didn't notice at first.
Versions:
- pvlib: 0.7.1+25.gc7b1c0e
- pandas: 0.24.2
- python: 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)]