Skip to content

Commit 9cb7a4f

Browse files
committed
Correcting file formatting.
1 parent 3cef534 commit 9cb7a4f

File tree

3 files changed

+9
-1125
lines changed

3 files changed

+9
-1125
lines changed
+6-160
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import pytest
1+
from datetime import datetime
22

3-
from numpy.random import randn
43
import numpy as np
5-
from datetime import datetime
4+
import pytest
5+
from numpy.random import randn
6+
67
import pandas as pd
7-
from pandas import (Series, DataFrame, bdate_range,
8-
notna)
98
import pandas.core.window as rwindow
10-
from pandas.errors import UnsupportedFunctionCall
119
import pandas.util.testing as tm
10+
from pandas import DataFrame, Series, bdate_range
11+
from pandas.errors import UnsupportedFunctionCall
1212

1313
N, K = 100, 10
1414

@@ -109,157 +109,3 @@ def test_missing_minp_zero(self):
109109
result = x.expanding(min_periods=1).sum()
110110
expected = pd.Series([np.nan])
111111
tm.assert_series_equal(result, expected)
112-
113-
114-
# create the data only once as we are not setting it
115-
def _create_consistency_data():
116-
def create_series():
117-
return [Series(),
118-
Series([np.nan]),
119-
Series([np.nan, np.nan]),
120-
Series([3.]),
121-
Series([np.nan, 3.]),
122-
Series([3., np.nan]),
123-
Series([1., 3.]),
124-
Series([2., 2.]),
125-
Series([3., 1.]),
126-
Series([5., 5., 5., 5., np.nan, np.nan, np.nan, 5., 5., np.nan,
127-
np.nan]),
128-
Series([np.nan, 5., 5., 5., np.nan, np.nan, np.nan, 5., 5.,
129-
np.nan, np.nan]),
130-
Series([np.nan, np.nan, 5., 5., np.nan, np.nan, np.nan, 5., 5.,
131-
np.nan, np.nan]),
132-
Series([np.nan, 3., np.nan, 3., 4., 5., 6., np.nan, np.nan, 7.,
133-
12., 13., 14., 15.]),
134-
Series([np.nan, 5., np.nan, 2., 4., 0., 9., np.nan, np.nan, 3.,
135-
12., 13., 14., 15.]),
136-
Series([2., 3., np.nan, 3., 4., 5., 6., np.nan, np.nan, 7.,
137-
12., 13., 14., 15.]),
138-
Series([2., 5., np.nan, 2., 4., 0., 9., np.nan, np.nan, 3.,
139-
12., 13., 14., 15.]),
140-
Series(range(10)),
141-
Series(range(20, 0, -2)), ]
142-
143-
def create_dataframes():
144-
return ([DataFrame(),
145-
DataFrame(columns=['a']),
146-
DataFrame(columns=['a', 'a']),
147-
DataFrame(columns=['a', 'b']),
148-
DataFrame(np.arange(10).reshape((5, 2))),
149-
DataFrame(np.arange(25).reshape((5, 5))),
150-
DataFrame(np.arange(25).reshape((5, 5)),
151-
columns=['a', 'b', 99, 'd', 'd'])] +
152-
[DataFrame(s) for s in create_series()])
153-
154-
def is_constant(x):
155-
values = x.values.ravel()
156-
return len(set(values[notna(values)])) == 1
157-
158-
def no_nans(x):
159-
return x.notna().all().all()
160-
161-
# data is a tuple(object, is_contant, no_nans)
162-
data = create_series() + create_dataframes()
163-
164-
return [(x, is_constant(x), no_nans(x)) for x in data]
165-
166-
167-
_consistency_data = _create_consistency_data()
168-
169-
170-
class TestGrouperGrouping(object):
171-
172-
def setup_method(self, method):
173-
self.series = Series(np.arange(10))
174-
self.frame = DataFrame({'A': [1] * 20 + [2] * 12 + [3] * 8,
175-
'B': np.arange(40)})
176-
177-
def test_mutated(self):
178-
179-
def f():
180-
self.frame.groupby('A', foo=1)
181-
pytest.raises(TypeError, f)
182-
183-
g = self.frame.groupby('A')
184-
assert not g.mutated
185-
g = self.frame.groupby('A', mutated=True)
186-
assert g.mutated
187-
188-
def test_getitem(self):
189-
g = self.frame.groupby('A')
190-
g_mutated = self.frame.groupby('A', mutated=True)
191-
192-
expected = g_mutated.B.apply(lambda x: x.rolling(2).mean())
193-
194-
result = g.rolling(2).mean().B
195-
tm.assert_series_equal(result, expected)
196-
197-
result = g.rolling(2).B.mean()
198-
tm.assert_series_equal(result, expected)
199-
200-
result = g.B.rolling(2).mean()
201-
tm.assert_series_equal(result, expected)
202-
203-
result = self.frame.B.groupby(self.frame.A).rolling(2).mean()
204-
tm.assert_series_equal(result, expected)
205-
206-
def test_getitem_multiple(self):
207-
208-
# GH 13174
209-
g = self.frame.groupby('A')
210-
r = g.rolling(2)
211-
g_mutated = self.frame.groupby('A', mutated=True)
212-
expected = g_mutated.B.apply(lambda x: x.rolling(2).count())
213-
214-
result = r.B.count()
215-
tm.assert_series_equal(result, expected)
216-
217-
result = r.B.count()
218-
tm.assert_series_equal(result, expected)
219-
220-
def test_expanding(self):
221-
g = self.frame.groupby('A')
222-
r = g.expanding()
223-
224-
for f in ['sum', 'mean', 'min', 'max', 'count', 'kurt', 'skew']:
225-
226-
result = getattr(r, f)()
227-
expected = g.apply(lambda x: getattr(x.expanding(), f)())
228-
tm.assert_frame_equal(result, expected)
229-
230-
for f in ['std', 'var']:
231-
result = getattr(r, f)(ddof=0)
232-
expected = g.apply(lambda x: getattr(x.expanding(), f)(ddof=0))
233-
tm.assert_frame_equal(result, expected)
234-
235-
result = r.quantile(0.5)
236-
expected = g.apply(lambda x: x.expanding().quantile(0.5))
237-
tm.assert_frame_equal(result, expected)
238-
239-
def test_expanding_corr_cov(self):
240-
g = self.frame.groupby('A')
241-
r = g.expanding()
242-
243-
for f in ['corr', 'cov']:
244-
result = getattr(r, f)(self.frame)
245-
246-
def func(x):
247-
return getattr(x.expanding(), f)(self.frame)
248-
expected = g.apply(func)
249-
tm.assert_frame_equal(result, expected)
250-
251-
result = getattr(r.B, f)(pairwise=True)
252-
253-
def func(x):
254-
return getattr(x.B.expanding(), f)(pairwise=True)
255-
expected = g.apply(func)
256-
tm.assert_series_equal(result, expected)
257-
258-
def test_expanding_apply(self):
259-
g = self.frame.groupby('A')
260-
r = g.expanding()
261-
262-
# reduction
263-
result = r.apply(lambda x: x.sum())
264-
expected = g.apply(lambda x: x.expanding().apply(lambda y: y.sum()))
265-
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)