Skip to content

Commit edfa82a

Browse files
committed
Addressed PR comments
1 parent 0d4c58a commit edfa82a

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

pandas/tests/test_groupby.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -824,31 +824,27 @@ def test_apply_issues(self):
824824
result = df.groupby('date').apply(lambda x: x['time'][x['value'].idxmax()])
825825
assert_series_equal(result, expected)
826826

827-
def test_time_field_bug_no_conversion(self):
828-
df = pd.DataFrame({
829-
'a': 1 * np.ones(10),
830-
'b': [datetime.now() for nn in range(10)],
831-
})
827+
def test_time_field_bug(self):
828+
# test a fix for GH issue 11324
832829

830+
df = pd.DataFrame({'a': 1,'b': [datetime.now() for nn in range(10)]})
833831

834-
def func(batch):
832+
def func_with_no_date(batch):
835833
return pd.Series({'c': 2})
836834

837-
dfg = df.groupby(by=['a']).apply(func)
838-
self.assertTrue('int' in dfg.dtypes[0].name)
839-
840-
def test_time_field_bug_conversion(self):
841-
df = pd.DataFrame({
842-
'a': 1 * np.ones(10),
843-
'b': [datetime.now() for nn in range(10)],
844-
})
835+
def func_with_date(batch):
836+
return pd.Series({'c': 2, 'b': datetime(2015, 1, 1)})
845837

838+
dfg_no_conversion = df.groupby(by=['a']).apply(func_with_no_date)
839+
dfg_no_conversion_expected = pd.DataFrame({'c': 2}, index=[1])
840+
dfg_no_conversion_expected.index.name = 'a'
846841

847-
def func(batch):
848-
return pd.Series({'c': 2, 'b': datetime.now()})
842+
dfg_conversion = df.groupby(by=['a']).apply(func_with_date)
843+
dfg_conversion_expected = pd.DataFrame({'b': datetime(2015, 1, 1), 'c': 2}, index=[1])
844+
dfg_conversion_expected.index.name = 'a'
849845

850-
dfg = df.groupby(by=['a']).apply(func)
851-
self.assertTrue('datetime' in dfg.dtypes[0].name)
846+
self.assert_frame_equal(dfg_no_conversion, dfg_no_conversion_expected)
847+
self.assert_frame_equal(dfg_conversion, dfg_conversion_expected)
852848

853849
def test_len(self):
854850
df = tm.makeTimeDataFrame()

0 commit comments

Comments
 (0)