Skip to content

Commit 9621315

Browse files
author
Giacomo Ferroni
committed
Added extra test and updated whatsnew
1 parent cb84935 commit 9621315

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

doc/source/whatsnew/v0.20.0.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,7 @@ Bug Fixes
362362

363363

364364
- Bug in ``pd.read_csv()`` for the C engine where ``usecols`` were being indexed incorrectly with ``parse_dates`` (:issue:`14792`)
365+
366+
367+
368+
- Bug in window function ``count`` not counting ``np.Inf`` (:issue:`12541`)

pandas/tests/test_window.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,35 @@ def f():
209209

210210
def test_count_nonnumeric_types(self):
211211
# GH12541
212-
df_inf = DataFrame({'x': [1, 2, 3], 'y': [1., 2., np.Inf]})
213-
df_date = DataFrame({'x': [1, 2, 3],
214-
'y': pd.date_range('20130101',periods=3)})
215-
df_inf_date = DataFrame({'x': [1, 2, 3], 'y': [1., 2., np.Inf],
216-
'z': pd.date_range('20170101',periods=3)})
217-
218-
expected_1 = DataFrame([[1,1],[2,2],[2,2]],
219-
columns=['x','y'], dtype=float)
220-
expected_2 = DataFrame([[1,1,1],[2,2,2],[2,2,2]],
221-
columns=['x','y','z'], dtype=float)
222-
223-
self.assert_frame_equal(df_inf.rolling(window=2).count(),
224-
expected_1)
225-
self.assert_frame_equal(df_date.rolling(window=2).count(),
226-
expected_1)
227-
self.assert_frame_equal(df_inf_date.rolling(window=2).count(),
228-
expected_2)
212+
cols = ['int', 'float', 'string', 'datetime', 'timedelta',
213+
'fl_inf', 'fl_nan', 'str_nan', 'dt_nat']
214+
215+
df = DataFrame(
216+
{'int': [1, 2, 3],
217+
'float': [4., 5., 6.],
218+
'string': list('abc'),
219+
'datetime': pd.date_range('20170101', periods=3),
220+
'timedelta': pd.timedelta_range('1 s', periods=3, freq='s'),
221+
'fl_inf': [1., 2., np.Inf],
222+
'fl_nan': [1., 2., np.NaN],
223+
'str_nan': ['aa', 'bb', np.NaN],
224+
'dt_nat': [pd.Timestamp('20170101'), pd.Timestamp('20170203'),
225+
pd.Timestamp(None)]},
226+
columns=cols)
227+
228+
expected = DataFrame(
229+
{'int': [1., 2., 2.],
230+
'float': [1., 2., 2.],
231+
'string': [1., 2., 2.],
232+
'datetime': [1., 2., 2.],
233+
'timedelta': [1., 2., 2.],
234+
'fl_inf': [1., 2., 2.],
235+
'fl_nan': [1., 2., 1.],
236+
'str_nan': [1., 2., 1.],
237+
'dt_nat': [1., 2., 1.]},
238+
columns=cols)
239+
240+
self.assert_frame_equal(df.rolling(window=2).count(), expected)
229241

230242
def test_window_with_args(self):
231243
tm._skip_if_no_scipy()

0 commit comments

Comments
 (0)