Skip to content

Commit c53bd70

Browse files
author
Diego Fernandez
committed
Add test for pandas-dev#13453 in test_resample and add note to whatsnew
1 parent 0daab80 commit c53bd70

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

doc/source/whatsnew/v0.20.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -585,3 +585,5 @@ Bug Fixes
585585
- Bug in ``Series.replace`` and ``DataFrame.replace`` which failed on empty replacement dicts (:issue:`15289`)
586586
- Bug in ``pd.melt()`` where passing a tuple value for ``value_vars`` caused a ``TypeError`` (:issue:`15348`)
587587
- Bug in ``.eval()`` which caused multiline evals to fail with local variables not on the first line (:issue:`15342`)
588+
589+
- Bug in ``groupby().nunique()`` when using ``TimeGrouper`` and a gap existed in the dates the values wouldn't be correct (:issue:`13453`)

pandas/tests/tseries/test_resample.py

+22
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,28 @@ def test_resample_nunique(self):
19391939
result = df.ID.groupby(pd.Grouper(freq='D')).nunique()
19401940
assert_series_equal(result, expected)
19411941

1942+
def test_resample_nunique_with_date_gap(self):
1943+
# GH 13453
1944+
index = pd.date_range('1-1-2000', '2-15-2000', freq='h')
1945+
index2 = pd.date_range('4-15-2000', '5-15-2000', freq='h')
1946+
index3 = index.append(index2)
1947+
s = pd.Series(range(len(index3)), index=index3)
1948+
r = s.resample('M')
1949+
1950+
# Since all elements are unique, these should all be the same
1951+
results = [
1952+
r.count(),
1953+
r.nunique(),
1954+
r.agg(pd.Series.nunique),
1955+
r.agg('nunique')
1956+
]
1957+
1958+
for res1 in results:
1959+
for res2 in results:
1960+
if res1 is not res2:
1961+
print('running')
1962+
assert_series_equal(res1, res2)
1963+
19421964
def test_resample_group_info(self): # GH10914
19431965
for n, k in product((10000, 100000), (10, 100, 1000)):
19441966
dr = date_range(start='2015-08-27', periods=n // 10, freq='T')

0 commit comments

Comments
 (0)