Skip to content

Commit 63f332a

Browse files
mroeschkejreback
authored andcommitted
TST: Add more tests for fixed issues (#30674)
1 parent 50ae37d commit 63f332a

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

pandas/tests/groupby/test_nth.py

+19
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ def test_first_last_nth_dtypes(df_mixed_floats):
8989
assert f.dtype == "int64"
9090

9191

92+
def test_first_strings_timestamps():
93+
# GH 11244
94+
test = pd.DataFrame(
95+
{
96+
pd.Timestamp("2012-01-01 00:00:00"): ["a", "b"],
97+
pd.Timestamp("2012-01-02 00:00:00"): ["c", "d"],
98+
"name": ["e", "e"],
99+
"aaaa": ["f", "g"],
100+
}
101+
)
102+
result = test.groupby("name").first()
103+
expected = DataFrame(
104+
[["a", "c", "f"]],
105+
columns=Index([Timestamp("2012-01-01"), Timestamp("2012-01-02"), "aaaa"]),
106+
index=Index(["e"], name="name"),
107+
)
108+
tm.assert_frame_equal(result, expected)
109+
110+
92111
def test_nth():
93112
df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=["A", "B"])
94113
g = df.groupby("A")

pandas/tests/io/parser/test_c_parser_only.py

+11
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,14 @@ def test_file_binary_mode(c_parser_only):
597597
with open(path, "rb") as f:
598598
result = parser.read_csv(f, header=None)
599599
tm.assert_frame_equal(result, expected)
600+
601+
602+
def test_unix_style_breaks(c_parser_only):
603+
# GH 11020
604+
parser = c_parser_only
605+
with tm.ensure_clean() as path:
606+
with open(path, "w", newline="\n") as f:
607+
f.write("blah\n\ncol_1,col_2,col_3\n\n")
608+
result = parser.read_csv(path, skiprows=2, encoding="utf-8", engine="c")
609+
expected = DataFrame(columns=["col_1", "col_2", "col_3"])
610+
tm.assert_frame_equal(result, expected)

pandas/tests/test_multilevel.py

+32
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,30 @@ def test_mixed_depth_drop(self):
13591359
)
13601360
tm.assert_frame_equal(expected, result)
13611361

1362+
def test_drop_multiindex_other_level_nan(self):
1363+
# GH 12754
1364+
df = (
1365+
DataFrame(
1366+
{
1367+
"A": ["one", "one", "two", "two"],
1368+
"B": [np.nan, 0.0, 1.0, 2.0],
1369+
"C": ["a", "b", "c", "c"],
1370+
"D": [1, 2, 3, 4],
1371+
}
1372+
)
1373+
.set_index(["A", "B", "C"])
1374+
.sort_index()
1375+
)
1376+
result = df.drop("c", level="C")
1377+
expected = DataFrame(
1378+
[2, 1],
1379+
columns=["D"],
1380+
index=pd.MultiIndex.from_tuples(
1381+
[("one", 0.0, "b"), ("one", np.nan, "a")], names=["A", "B", "C"]
1382+
),
1383+
)
1384+
tm.assert_frame_equal(result, expected)
1385+
13621386
def test_drop_nonunique(self):
13631387
df = DataFrame(
13641388
[
@@ -2286,6 +2310,14 @@ def test_sort_index_and_reconstruction_doc_example(self):
22862310

22872311
tm.assert_frame_equal(result, expected)
22882312

2313+
def test_sort_index_non_existent_label_multiindex(self):
2314+
# GH 12261
2315+
df = DataFrame(0, columns=[], index=pd.MultiIndex.from_product([[], []]))
2316+
df.loc["b", "2"] = 1
2317+
df.loc["a", "3"] = 1
2318+
result = df.sort_index().index.is_monotonic
2319+
assert result is True
2320+
22892321
def test_sort_index_reorder_on_ops(self):
22902322
# 15687
22912323
df = DataFrame(

0 commit comments

Comments
 (0)