Skip to content

Commit 0e2dec0

Browse files
author
Robin
committed
Fixed tests
1 parent 26db131 commit 0e2dec0

File tree

4 files changed

+32
-40
lines changed

4 files changed

+32
-40
lines changed

pandas/tests/frame/test_analytics.py

+9-20
Original file line numberDiff line numberDiff line change
@@ -809,18 +809,18 @@ def test_mode(self):
809809
"E": [8, 8, 1, 1, 3, 3]})
810810
tm.assert_frame_equal(df[["A"]].mode(),
811811
pd.DataFrame({"A": [12]}))
812-
expected = pd.Series([], dtype='int64', name='D').to_frame()
812+
expected = pd.Series([0, 1, 2, 3, 4, 5], dtype='int64', name='D').to_frame()
813813
tm.assert_frame_equal(df[["D"]].mode(), expected)
814814
expected = pd.Series([1, 3, 8], dtype='int64', name='E').to_frame()
815815
tm.assert_frame_equal(df[["E"]].mode(), expected)
816816
tm.assert_frame_equal(df[["A", "B"]].mode(),
817817
pd.DataFrame({"A": [12], "B": [10.]}))
818818
tm.assert_frame_equal(df.mode(),
819-
pd.DataFrame({"A": [12, np.nan, np.nan],
820-
"B": [10, np.nan, np.nan],
821-
"C": [8, 9, np.nan],
822-
"D": [np.nan, np.nan, np.nan],
823-
"E": [1, 3, 8]}))
819+
pd.DataFrame({"A": [12, np.nan, np.nan, np.nan, np.nan, np.nan],
820+
"B": [10, np.nan, np.nan, np.nan, np.nan, np.nan],
821+
"C": [8, 9, np.nan, np.nan, np.nan, np.nan],
822+
"D": [0, 1, 2, 3, 4, 5],
823+
"E": [1, 3, 8, np.nan, np.nan, np.nan]}))
824824

825825
# outputs in sorted order
826826
df["C"] = list(reversed(df["C"]))
@@ -837,20 +837,9 @@ def test_mode(self):
837837
df = pd.DataFrame({"A": np.arange(6, dtype='int64'),
838838
"B": pd.date_range('2011', periods=6),
839839
"C": list('abcdef')})
840-
exp = pd.DataFrame({"A": pd.Series([], dtype=df["A"].dtype),
841-
"B": pd.Series([], dtype=df["B"].dtype),
842-
"C": pd.Series([], dtype=df["C"].dtype)})
843-
tm.assert_frame_equal(df.mode(), exp)
844-
845-
# and also when not empty
846-
df.loc[1, "A"] = 0
847-
df.loc[4, "B"] = df.loc[3, "B"]
848-
df.loc[5, "C"] = 'e'
849-
exp = pd.DataFrame({"A": pd.Series([0], dtype=df["A"].dtype),
850-
"B": pd.Series([df.loc[3, "B"]],
851-
dtype=df["B"].dtype),
852-
"C": pd.Series(['e'], dtype=df["C"].dtype)})
853-
840+
exp = pd.DataFrame({"A": pd.Series(np.arange(6, dtype='int64'), dtype=df["A"].dtype),
841+
"B": pd.Series(pd.date_range('2011', periods=6), dtype=df["B"].dtype),
842+
"C": pd.Series(list('abcdef'), dtype=df["C"].dtype)})
854843
tm.assert_frame_equal(df.mode(), exp)
855844

856845
def test_operators_timedelta64(self):

pandas/tests/series/test_analytics.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ def test_mode(self):
130130
exp = Series([], dtype=np.float64)
131131
tm.assert_series_equal(Series([]).mode(), exp)
132132

133-
exp = Series([], dtype=np.int64)
133+
exp = Series([1], dtype=np.int64)
134134
tm.assert_series_equal(Series([1]).mode(), exp)
135135

136-
exp = Series([], dtype=np.object)
136+
exp = Series(['a','b','c'], dtype=np.object)
137137
tm.assert_series_equal(Series(['a', 'b', 'c']).mode(), exp)
138138

139139
# Test numerical data types.
@@ -169,7 +169,8 @@ def test_mode(self):
169169
tm.assert_series_equal(s.mode(), exp)
170170

171171
# Test datetime types.
172-
exp = Series([], dtype="M8[ns]")
172+
exp = Series(['1900-05-03', '2011-01-03',
173+
'2013-01-02'], dtype='M8[ns]')
173174
s = Series(['2011-01-03', '2013-01-02',
174175
'1900-05-03'], dtype='M8[ns]')
175176
tm.assert_series_equal(s.mode(), exp)
@@ -180,7 +181,7 @@ def test_mode(self):
180181
tm.assert_series_equal(s.mode(), exp)
181182

182183
# gh-5986: Test timedelta types.
183-
exp = Series([], dtype='timedelta64[ns]')
184+
exp = Series(['-1 days', '0 days', '1 days'], dtype='timedelta64[ns]')
184185
s = Series(['1 days', '-1 days', '0 days'],
185186
dtype='timedelta64[ns]')
186187
tm.assert_series_equal(s.mode(), exp)
@@ -200,13 +201,13 @@ def test_mode(self):
200201
s = Series([1, 2**63, 2**63], dtype=np.uint64)
201202
tm.assert_series_equal(s.mode(), exp)
202203

203-
exp = Series([], dtype=np.uint64)
204+
exp = Series([1, 2**63], dtype=np.uint64)
204205
s = Series([1, 2**63], dtype=np.uint64)
205206
tm.assert_series_equal(s.mode(), exp)
206207

207208
# Test category dtype.
208209
c = Categorical([1, 2])
209-
exp = Categorical([], categories=[1, 2])
210+
exp = Categorical([1, 2], categories=[1, 2])
210211
exp = Series(exp, dtype='category')
211212
tm.assert_series_equal(Series(c).mode(), exp)
212213

pandas/tests/test_algos.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -1256,12 +1256,6 @@ def test_no_mode(self):
12561256
exp = Series([], dtype=np.float64)
12571257
tm.assert_series_equal(algos.mode([]), exp)
12581258

1259-
exp = Series([], dtype=np.int)
1260-
tm.assert_series_equal(algos.mode([1]), exp)
1261-
1262-
exp = Series([], dtype=np.object)
1263-
tm.assert_series_equal(algos.mode(['a', 'b', 'c']), exp)
1264-
12651259
def test_mode_single(self):
12661260
exp_single = [1]
12671261
data_single = [1]
@@ -1271,6 +1265,12 @@ def test_mode_single(self):
12711265
exp = Series(exp_single, dtype=dt)
12721266
tm.assert_series_equal(algos.mode(s), exp)
12731267

1268+
exp = Series([1], dtype=np.int)
1269+
tm.assert_series_equal(algos.mode([1]), exp)
1270+
1271+
exp = Series(['a', 'b', 'c'], dtype=np.object)
1272+
tm.assert_series_equal(algos.mode(['a', 'b', 'c']), exp)
1273+
12741274
def test_number_mode(self):
12751275
exp_single = [1]
12761276
data_single = [1] * 5 + [2] * 3
@@ -1304,7 +1304,8 @@ def test_strobj_mode(self):
13041304
tm.assert_series_equal(algos.mode(s), exp)
13051305

13061306
def test_datelike_mode(self):
1307-
exp = Series([], dtype="M8[ns]")
1307+
exp = Series(['1900-05-03', '2011-01-03',
1308+
'2013-01-02'], dtype="M8[ns]")
13081309
s = Series(['2011-01-03', '2013-01-02',
13091310
'1900-05-03'], dtype='M8[ns]')
13101311
tm.assert_series_equal(algos.mode(s), exp)
@@ -1315,7 +1316,8 @@ def test_datelike_mode(self):
13151316
tm.assert_series_equal(algos.mode(s), exp)
13161317

13171318
def test_timedelta_mode(self):
1318-
exp = Series([], dtype='timedelta64[ns]')
1319+
exp = Series(['-1 days', '0 days', '1 days'],
1320+
dtype='timedelta64[ns]')
13191321
s = Series(['1 days', '-1 days', '0 days'],
13201322
dtype='timedelta64[ns]')
13211323
tm.assert_series_equal(algos.mode(s), exp)
@@ -1335,13 +1337,13 @@ def test_uint64_overflow(self):
13351337
s = Series([1, 2**63, 2**63], dtype=np.uint64)
13361338
tm.assert_series_equal(algos.mode(s), exp)
13371339

1338-
exp = Series([], dtype=np.uint64)
1340+
exp = Series([1, 2**63], dtype=np.uint64)
13391341
s = Series([1, 2**63], dtype=np.uint64)
13401342
tm.assert_series_equal(algos.mode(s), exp)
13411343

13421344
def test_categorical(self):
13431345
c = Categorical([1, 2])
1344-
exp = Series([], dtype=np.int64)
1346+
exp = Series([1, 2], dtype=np.int64)
13451347
tm.assert_series_equal(algos.mode(c), exp)
13461348

13471349
c = Categorical([1, 'a', 'a'])
@@ -1354,7 +1356,7 @@ def test_categorical(self):
13541356

13551357
def test_index(self):
13561358
idx = Index([1, 2, 3])
1357-
exp = Series([], dtype=np.int64)
1359+
exp = Series([1, 2, 3], dtype=np.int64)
13581360
tm.assert_series_equal(algos.mode(idx), exp)
13591361

13601362
idx = Index([1, 'a', 'a'])

pandas/tests/test_categorical.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1372,13 +1372,13 @@ def test_mode(self):
13721372
s = Categorical([1, 2, 3, 4, 5], categories=[5, 4, 3, 2, 1],
13731373
ordered=True)
13741374
res = s.mode()
1375-
exp = Categorical([], categories=[5, 4, 3, 2, 1], ordered=True)
1375+
exp = Categorical([5, 4, 3, 2, 1], categories=[5, 4, 3, 2, 1], ordered=True)
13761376
tm.assert_categorical_equal(res, exp)
13771377
# NaN should not become the mode!
13781378
s = Categorical([np.nan, np.nan, np.nan, 4, 5],
13791379
categories=[5, 4, 3, 2, 1], ordered=True)
13801380
res = s.mode()
1381-
exp = Categorical([], categories=[5, 4, 3, 2, 1], ordered=True)
1381+
exp = Categorical([5, 4], categories=[5, 4, 3, 2, 1], ordered=True)
13821382
tm.assert_categorical_equal(res, exp)
13831383
s = Categorical([np.nan, np.nan, np.nan, 4, 5, 4],
13841384
categories=[5, 4, 3, 2, 1], ordered=True)
@@ -2980,7 +2980,7 @@ def test_mode(self):
29802980
s = Series(Categorical([1, 2, 3, 4, 5], categories=[5, 4, 3, 2, 1],
29812981
ordered=True))
29822982
res = s.mode()
2983-
exp = Series(Categorical([], categories=[5, 4, 3, 2, 1], ordered=True))
2983+
exp = Series(Categorical([5, 4, 3, 2, 1], categories=[5, 4, 3, 2, 1], ordered=True))
29842984
tm.assert_series_equal(res, exp)
29852985

29862986
def test_value_counts(self):

0 commit comments

Comments
 (0)