Skip to content

Commit aab7d7c

Browse files
mroeschkeTomAugspurger
authored andcommitted
TST: Regression testing for fixed issues (#30554)
* TST: Regression testing for fixed issues
1 parent 052ac7b commit aab7d7c

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed

pandas/tests/groupby/test_groupby.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,20 @@ def test_groupby_multiple_columns(df, op):
588588
tm.assert_series_equal(result, expected)
589589

590590

591+
def test_as_index_select_column():
592+
# GH 5764
593+
df = pd.DataFrame([[1, 2], [1, 4], [5, 6]], columns=["A", "B"])
594+
result = df.groupby("A", as_index=False)["B"].get_group(1)
595+
expected = pd.Series([2, 4], name="B")
596+
tm.assert_series_equal(result, expected)
597+
598+
result = df.groupby("A", as_index=False)["B"].apply(lambda x: x.cumsum())
599+
expected = pd.Series(
600+
[2, 6, 6], name="B", index=pd.MultiIndex.from_tuples([(0, 0), (0, 1), (1, 2)])
601+
)
602+
tm.assert_series_equal(result, expected)
603+
604+
591605
def test_groupby_as_index_agg(df):
592606
grouped = df.groupby("A", as_index=False)
593607

pandas/tests/groupby/test_transform.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,3 +1133,40 @@ def func(grp):
11331133

11341134
expected = pd.DataFrame([2, -2, 2, 4], columns=["B"])
11351135
tm.assert_frame_equal(result, expected)
1136+
1137+
1138+
def test_transform_lambda_indexing():
1139+
# GH 7883
1140+
df = pd.DataFrame(
1141+
{
1142+
"A": ["foo", "bar", "foo", "bar", "foo", "flux", "foo", "flux"],
1143+
"B": ["one", "one", "two", "three", "two", "six", "five", "three"],
1144+
"C": range(8),
1145+
"D": range(8),
1146+
"E": range(8),
1147+
}
1148+
)
1149+
df = df.set_index(["A", "B"])
1150+
df = df.sort_index()
1151+
result = df.groupby(level="A").transform(lambda x: x.iloc[-1])
1152+
expected = DataFrame(
1153+
{
1154+
"C": [3, 3, 7, 7, 4, 4, 4, 4],
1155+
"D": [3, 3, 7, 7, 4, 4, 4, 4],
1156+
"E": [3, 3, 7, 7, 4, 4, 4, 4],
1157+
},
1158+
index=MultiIndex.from_tuples(
1159+
[
1160+
("bar", "one"),
1161+
("bar", "three"),
1162+
("flux", "six"),
1163+
("flux", "three"),
1164+
("foo", "five"),
1165+
("foo", "one"),
1166+
("foo", "two"),
1167+
("foo", "two"),
1168+
],
1169+
names=["A", "B"],
1170+
),
1171+
)
1172+
tm.assert_frame_equal(result, expected)

pandas/tests/indexes/test_numeric.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,12 @@ def test_get_indexer(self):
736736
expected = np.array([0, 1, 1, 2, 2, 3, 3, 4, 4, 5], dtype=np.intp)
737737
tm.assert_numpy_array_equal(indexer, expected)
738738

739+
def test_get_indexer_nan(self):
740+
# GH 7820
741+
result = Index([1, 2, np.nan]).get_indexer([np.nan])
742+
expected = np.array([2], dtype=np.intp)
743+
tm.assert_numpy_array_equal(result, expected)
744+
739745
def test_intersection(self):
740746
index = self.create_index()
741747
other = Index([1, 2, 3, 4, 5])

pandas/tests/indexing/test_loc.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,3 +966,17 @@ def test_loc_getitem_label_list_integer_labels(
966966
expected = df.iloc[:, expected_columns]
967967
result = df.loc[["A", "B", "C"], column_key]
968968
tm.assert_frame_equal(result, expected, check_column_type=check_column_type)
969+
970+
971+
def test_loc_setitem_float_intindex():
972+
# GH 8720
973+
rand_data = np.random.randn(8, 4)
974+
result = pd.DataFrame(rand_data)
975+
result.loc[:, 0.5] = np.nan
976+
expected_data = np.hstack((rand_data, np.array([np.nan] * 8).reshape(8, 1)))
977+
expected = pd.DataFrame(expected_data, columns=[0.0, 1.0, 2.0, 3.0, 0.5])
978+
tm.assert_frame_equal(result, expected)
979+
980+
result = pd.DataFrame(rand_data)
981+
result.loc[:, 0.5] = np.nan
982+
tm.assert_frame_equal(result, expected)

pandas/tests/io/formats/test_to_csv.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import io
12
import os
23
import sys
34

@@ -563,3 +564,17 @@ def test_to_csv_na_rep_long_string(self, df_new_type):
563564
result = df.to_csv(index=False, na_rep="mynull", encoding="ascii")
564565

565566
assert expected == result
567+
568+
def test_to_csv_timedelta_precision(self):
569+
# GH 6783
570+
s = pd.Series([1, 1]).astype("timedelta64[ns]")
571+
buf = io.StringIO()
572+
s.to_csv(buf)
573+
result = buf.getvalue()
574+
expected_rows = [
575+
",0",
576+
"0,0 days 00:00:00.000000001",
577+
"1,0 days 00:00:00.000000001",
578+
]
579+
expected = tm.convert_rows_list_to_csv_str(expected_rows)
580+
assert result == expected

pandas/tests/io/parser/test_common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,3 +2207,13 @@ def test_first_row_bom(all_parsers):
22072207
result = parser.read_csv(StringIO(data), delimiter="\t")
22082208
expected = DataFrame(columns=["Head1", "Head2", "Head3"])
22092209
tm.assert_frame_equal(result, expected)
2210+
2211+
2212+
def test_integer_precision(all_parsers):
2213+
# Gh 7072
2214+
s = """1,1;0;0;0;1;1;3844;3844;3844;1;1;1;1;1;1;0;0;1;1;0;0,,,4321583677327450765
2215+
5,1;0;0;0;1;1;843;843;843;1;1;1;1;1;1;0;0;1;1;0;0,64.0,;,4321113141090630389"""
2216+
parser = all_parsers
2217+
result = parser.read_csv(StringIO(s), header=None)[4]
2218+
expected = Series([4321583677327450765, 4321113141090630389], name=4)
2219+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)