Skip to content

Commit 2bbc0c2

Browse files
rbenesjreback
authored andcommitted
ENH: Poisson exponential window (#26243)
1 parent f65742c commit 2bbc0c2

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

doc/source/user_guide/computation.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ The list of recognized types are the `scipy.signal window functions
365365
* ``kaiser`` (needs beta)
366366
* ``gaussian`` (needs std)
367367
* ``general_gaussian`` (needs power, width)
368-
* ``slepian`` (needs width).
368+
* ``slepian`` (needs width)
369+
* ``exponential`` (needs tau).
369370

370371
.. ipython:: python
371372

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Other Enhancements
3939
- :class:`datetime.timezone` objects are now supported as arguments to timezone methods and constructors (:issue:`25065`)
4040
- :meth:`DataFrame.query` and :meth:`DataFrame.eval` now supports quoting column names with backticks to refer to names with spaces (:issue:`6508`)
4141
- :func:`merge_asof` now gives a more clear error message when merge keys are categoricals that are not equal (:issue:`26136`)
42+
- :meth:`pandas.core.window.Rolling` supports exponential (or Poisson) window type (:issue:`21303`)
4243

4344
.. _whatsnew_0250.api_breaking:
4445

pandas/core/window.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ class Window(_Window):
504504
* ``kaiser`` (needs beta)
505505
* ``gaussian`` (needs std)
506506
* ``general_gaussian`` (needs power, width)
507-
* ``slepian`` (needs width).
507+
* ``slepian`` (needs width)
508+
* ``exponential`` (needs tau), center is set to None.
508509
509510
If ``win_type=None`` all points are evenly weighted. To learn more about
510511
different window types see `scipy.signal window functions
@@ -623,11 +624,19 @@ def _validate_win_type(win_type, kwargs):
623624
arg_map = {'kaiser': ['beta'],
624625
'gaussian': ['std'],
625626
'general_gaussian': ['power', 'width'],
626-
'slepian': ['width']}
627+
'slepian': ['width'],
628+
'exponential': ['tau'],
629+
}
630+
627631
if win_type in arg_map:
628-
return tuple([win_type] + _pop_args(win_type,
629-
arg_map[win_type],
630-
kwargs))
632+
win_args = _pop_args(win_type, arg_map[win_type], kwargs)
633+
if win_type == 'exponential':
634+
# exponential window requires the first arg (center)
635+
# to be set to None (necessary for symmetric window)
636+
win_args.insert(0, None)
637+
638+
return tuple([win_type] + win_args)
639+
631640
return win_type
632641

633642
def _pop_args(win_type, arg_names, kwargs):

pandas/tests/test_window.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def win_types(request):
4242
return request.param
4343

4444

45-
@pytest.fixture(params=['kaiser', 'gaussian', 'general_gaussian'])
45+
@pytest.fixture(params=['kaiser', 'gaussian', 'general_gaussian',
46+
'exponential'])
4647
def win_types_special(request):
4748
return request.param
4849

@@ -1260,7 +1261,8 @@ def test_cmov_window_special(self, win_types_special):
12601261
kwds = {
12611262
'kaiser': {'beta': 1.},
12621263
'gaussian': {'std': 1.},
1263-
'general_gaussian': {'power': 2., 'width': 2.}}
1264+
'general_gaussian': {'power': 2., 'width': 2.},
1265+
'exponential': {'tau': 10}}
12641266

12651267
vals = np.array([6.95, 15.21, 4.72, 9.12, 13.81, 13.49, 16.68, 9.48,
12661268
10.63, 14.48])
@@ -1271,7 +1273,9 @@ def test_cmov_window_special(self, win_types_special):
12711273
'general_gaussian': [np.nan, np.nan, 9.85011, 10.71589, 11.73161,
12721274
13.08516, 12.95111, 12.74577, np.nan, np.nan],
12731275
'kaiser': [np.nan, np.nan, 9.86851, 11.02969, 11.65161, 12.75129,
1274-
12.90702, 12.83757, np.nan, np.nan]
1276+
12.90702, 12.83757, np.nan, np.nan],
1277+
'exponential': [np.nan, np.nan, 9.83364, 11.10472, 11.64551,
1278+
12.66138, 12.92379, 12.83770, np.nan, np.nan],
12751279
}
12761280

12771281
xp = Series(xps[win_types_special])
@@ -1287,7 +1291,8 @@ def test_cmov_window_special_linear_range(self, win_types_special):
12871291
'kaiser': {'beta': 1.},
12881292
'gaussian': {'std': 1.},
12891293
'general_gaussian': {'power': 2., 'width': 2.},
1290-
'slepian': {'width': 0.5}}
1294+
'slepian': {'width': 0.5},
1295+
'exponential': {'tau': 10}}
12911296

12921297
vals = np.array(range(10), dtype=np.float)
12931298
xp = vals.copy()

0 commit comments

Comments
 (0)