Skip to content

Commit 7e75e4a

Browse files
Maximiliano Grecojreback
Maximiliano Greco
authored andcommitted
Fixed WOM offset when n=0 (#20549)
1 parent 336fba7 commit 7e75e4a

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

doc/source/api.rst

+2
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,7 @@ Standard moving window functions
21062106
Rolling.skew
21072107
Rolling.kurt
21082108
Rolling.apply
2109+
Rolling.aggregate
21092110
Rolling.quantile
21102111
Window.mean
21112112
Window.sum
@@ -2133,6 +2134,7 @@ Standard expanding window functions
21332134
Expanding.skew
21342135
Expanding.kurt
21352136
Expanding.apply
2137+
Expanding.aggregate
21362138
Expanding.quantile
21372139

21382140
Exponentially-weighted moving window functions

doc/source/whatsnew/v0.23.0.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ Other Enhancements
438438
``SQLAlchemy`` dialects supporting multivalue inserts include: ``mysql``, ``postgresql``, ``sqlite`` and any dialect with ``supports_multivalues_insert``. (:issue:`14315`, :issue:`8953`)
439439
- :func:`read_html` now accepts a ``displayed_only`` keyword argument to controls whether or not hidden elements are parsed (``True`` by default) (:issue:`20027`)
440440
- zip compression is supported via ``compression=zip`` in :func:`DataFrame.to_pickle`, :func:`Series.to_pickle`, :func:`DataFrame.to_csv`, :func:`Series.to_csv`, :func:`DataFrame.to_json`, :func:`Series.to_json`. (:issue:`17778`)
441+
- :class:`WeekOfMonth` constructor now supports ``n=0`` (:issue:`20517`).
441442
- :class:`DataFrame` and :class:`Series` now support matrix multiplication (```@```) operator (:issue:`10259`) for Python>=3.5
442443
- Updated ``to_gbq`` and ``read_gbq`` signature and documentation to reflect changes from
443444
the Pandas-GBQ library version 0.4.0. Adds intersphinx mapping to Pandas-GBQ
@@ -847,7 +848,7 @@ Other API Changes
847848
- :func:`DatetimeIndex.strftime` and :func:`PeriodIndex.strftime` now return an ``Index`` instead of a numpy array to be consistent with similar accessors (:issue:`20127`)
848849
- Constructing a Series from a list of length 1 no longer broadcasts this list when a longer index is specified (:issue:`19714`, :issue:`20391`).
849850
- :func:`DataFrame.to_dict` with ``orient='index'`` no longer casts int columns to float for a DataFrame with only int and float columns (:issue:`18580`)
850-
- A user-defined-function that is passed to :func:`Series.rolling().aggregate() <pandas.core.window.Rolling.aggregate>`, :func:`DataFrame.rolling().aggregate() <pandas.core.window.Rolling.aggregate>`, or its expanding cousins, will now *always* be passed a ``Series``, rather than an ``np.array``; ``.apply()`` only has the ``raw`` keyword, see :ref:`here <whatsnew_0230.enhancements.window_raw>`. This is consistent with the signatures of ``.aggregate()`` across pandas (:issue:`20584`)
851+
- A user-defined-function that is passed to :func:`Series.rolling().aggregate() <pandas.core.window.Rolling.aggregate>`, :func:`DataFrame.rolling().aggregate() <pandas.core.window.Rolling.aggregate>`, or its expanding cousins, will now *always* be passed a ``Series``, rather than a ``np.array``; ``.apply()`` only has the ``raw`` keyword, see :ref:`here <whatsnew_0230.enhancements.window_raw>`. This is consistent with the signatures of ``.aggregate()`` across pandas (:issue:`20584`)
851852

852853
.. _whatsnew_0230.deprecations:
853854

pandas/tests/indexes/datetimes/test_date_range.py

+6
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ def test_catch_infinite_loop(self):
236236
pytest.raises(Exception, date_range, datetime(2011, 11, 11),
237237
datetime(2011, 11, 12), freq=offset)
238238

239+
@pytest.mark.parametrize('periods', (1, 2))
240+
def test_wom_len(self, periods):
241+
# https://github.com/pandas-dev/pandas/issues/20517
242+
res = date_range(start='20110101', periods=periods, freq='WOM-1MON')
243+
assert len(res) == periods
244+
239245

240246
class TestGenRangeGeneration(object):
241247

pandas/tests/tseries/offsets/test_offsets.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -2228,8 +2228,6 @@ class TestWeekOfMonth(Base):
22282228
_offset = WeekOfMonth
22292229

22302230
def test_constructor(self):
2231-
tm.assert_raises_regex(ValueError, "^N cannot be 0",
2232-
WeekOfMonth, n=0, week=1, weekday=1)
22332231
tm.assert_raises_regex(ValueError, "^Week", WeekOfMonth,
22342232
n=1, week=4, weekday=0)
22352233
tm.assert_raises_regex(ValueError, "^Week", WeekOfMonth,
@@ -2261,6 +2259,19 @@ def test_offset(self):
22612259
(-1, 2, 1, date3, datetime(2010, 12, 21)),
22622260
(-1, 2, 1, date4, datetime(2011, 1, 18)),
22632261

2262+
(0, 0, 1, date1, datetime(2011, 1, 4)),
2263+
(0, 0, 1, date2, datetime(2011, 2, 1)),
2264+
(0, 0, 1, date3, datetime(2011, 2, 1)),
2265+
(0, 0, 1, date4, datetime(2011, 2, 1)),
2266+
(0, 1, 1, date1, datetime(2011, 1, 11)),
2267+
(0, 1, 1, date2, datetime(2011, 1, 11)),
2268+
(0, 1, 1, date3, datetime(2011, 2, 8)),
2269+
(0, 1, 1, date4, datetime(2011, 2, 8)),
2270+
(0, 0, 1, date1, datetime(2011, 1, 4)),
2271+
(0, 1, 1, date2, datetime(2011, 1, 11)),
2272+
(0, 2, 1, date3, datetime(2011, 1, 18)),
2273+
(0, 3, 1, date4, datetime(2011, 1, 25)),
2274+
22642275
(1, 0, 0, date1, datetime(2011, 2, 7)),
22652276
(1, 0, 0, date2, datetime(2011, 2, 7)),
22662277
(1, 0, 0, date3, datetime(2011, 2, 7)),

pandas/tseries/offsets.py

-3
Original file line numberDiff line numberDiff line change
@@ -1461,9 +1461,6 @@ def __init__(self, n=1, normalize=False, week=0, weekday=0):
14611461
self.weekday = weekday
14621462
self.week = week
14631463

1464-
if self.n == 0:
1465-
raise ValueError('N cannot be 0')
1466-
14671464
if self.weekday < 0 or self.weekday > 6:
14681465
raise ValueError('Day must be 0<=day<=6, got {day}'
14691466
.format(day=self.weekday))

0 commit comments

Comments
 (0)