Skip to content

Commit 99f498b

Browse files
committed
Exponential window can be used
1 parent 94c8c94 commit 99f498b

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

pandas/core/window.py

+16-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,20 +624,30 @@ 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': ['center', 'tau']}
629+
immutable_args_map = {'exponential': {'center': None}}
630+
627631
if win_type in arg_map:
632+
immutable_args = immutable_args_map.get(win_type, {})
628633
return tuple([win_type] + _pop_args(win_type,
629634
arg_map[win_type],
635+
immutable_args,
630636
kwargs))
637+
631638
return win_type
632639

633-
def _pop_args(win_type, arg_names, kwargs):
640+
def _pop_args(win_type, arg_names, immutable_args, kwargs):
634641
msg = '%s window requires %%s' % win_type
635642
all_args = []
636643
for n in arg_names:
637-
if n not in kwargs:
644+
if n in immutable_args:
645+
value = immutable_args[n]
646+
elif n in kwargs:
647+
value = kwargs.pop(n)
648+
else:
638649
raise ValueError(msg % n)
639-
all_args.append(kwargs.pop(n))
650+
all_args.append(value)
640651
return all_args
641652

642653
win_type = _validate_win_type(self.win_type, 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)