Skip to content

Commit 6f75d10

Browse files
authored
TST: Old issues (#44245)
1 parent 99f6178 commit 6f75d10

File tree

7 files changed

+80
-0
lines changed

7 files changed

+80
-0
lines changed

pandas/tests/apply/test_series_apply.py

+12
Original file line numberDiff line numberDiff line change
@@ -878,3 +878,15 @@ def test_apply_dictlike_transformer(string_series, ops):
878878
expected.name = string_series.name
879879
result = string_series.apply(ops)
880880
tm.assert_series_equal(result, expected)
881+
882+
883+
def test_apply_retains_column_name():
884+
# GH 16380
885+
df = DataFrame({"x": range(3)}, Index(range(3), name="x"))
886+
result = df.x.apply(lambda x: Series(range(x + 1), Index(range(x + 1), name="y")))
887+
expected = DataFrame(
888+
[[0.0, np.nan, np.nan], [0.0, 1.0, np.nan], [0.0, 1.0, 2.0]],
889+
columns=Index(range(3), name="y"),
890+
index=Index(range(3), name="x"),
891+
)
892+
tm.assert_frame_equal(result, expected)

pandas/tests/arithmetic/test_categorical.py

+10
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ def test_categorical_nan_equality(self):
1313
expected = Series([True, True, True, False])
1414
result = cat == cat
1515
tm.assert_series_equal(result, expected)
16+
17+
def test_categorical_tuple_equality(self):
18+
# GH 18050
19+
ser = Series([(0, 0), (0, 1), (0, 0), (1, 0), (1, 1)])
20+
expected = Series([True, False, True, False, False])
21+
result = ser == (0, 0)
22+
tm.assert_series_equal(result, expected)
23+
24+
result = ser.astype("category") == (0, 0)
25+
tm.assert_series_equal(result, expected)

pandas/tests/frame/test_stack_unstack.py

+18
Original file line numberDiff line numberDiff line change
@@ -2081,3 +2081,21 @@ def test_unstack_categorical_columns(self):
20812081
)
20822082
expected.columns = MultiIndex.from_tuples([("cat", 0), ("cat", 1)])
20832083
tm.assert_frame_equal(result, expected)
2084+
2085+
def test_stack_unsorted(self):
2086+
# GH 16925
2087+
PAE = ["ITA", "FRA"]
2088+
VAR = ["A1", "A2"]
2089+
TYP = ["CRT", "DBT", "NET"]
2090+
MI = MultiIndex.from_product([PAE, VAR, TYP], names=["PAE", "VAR", "TYP"])
2091+
2092+
V = list(range(len(MI)))
2093+
DF = DataFrame(data=V, index=MI, columns=["VALUE"])
2094+
2095+
DF = DF.unstack(["VAR", "TYP"])
2096+
DF.columns = DF.columns.droplevel(0)
2097+
DF.loc[:, ("A0", "NET")] = 9999
2098+
2099+
result = DF.stack(["VAR", "TYP"]).sort_index()
2100+
expected = DF.sort_index(axis=1).stack(["VAR", "TYP"]).sort_index()
2101+
tm.assert_series_equal(result, expected)

pandas/tests/groupby/test_function.py

+10
Original file line numberDiff line numberDiff line change
@@ -1155,3 +1155,13 @@ def test_groupby_sum_below_mincount_nullable_integer():
11551155
result = grouped.sum(min_count=2)
11561156
expected = DataFrame({"b": [pd.NA] * 3, "c": [pd.NA] * 3}, dtype="Int64", index=idx)
11571157
tm.assert_frame_equal(result, expected)
1158+
1159+
1160+
def test_mean_on_timedelta():
1161+
# GH 17382
1162+
df = DataFrame({"time": pd.to_timedelta(range(10)), "cat": ["A", "B"] * 5})
1163+
result = df.groupby("cat")["time"].mean()
1164+
expected = Series(
1165+
pd.to_timedelta([4, 5]), name="time", index=Index(["A", "B"], name="cat")
1166+
)
1167+
tm.assert_series_equal(result, expected)

pandas/tests/groupby/test_rank.py

+13
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,16 @@ def test_groupby_axis0_cummax_axis1():
648648
expected = df[[0, 1]].astype(np.float64)
649649
expected[2] = expected[1]
650650
tm.assert_frame_equal(cmax, expected)
651+
652+
653+
def test_non_unique_index():
654+
# GH 16577
655+
df = DataFrame(
656+
{"A": [1.0, 2.0, 3.0, np.nan], "value": 1.0},
657+
index=[pd.Timestamp("20170101", tz="US/Eastern")] * 4,
658+
)
659+
result = df.groupby([df.index, "A"]).value.rank(ascending=True, pct=True)
660+
expected = Series(
661+
[1.0] * 4, index=[pd.Timestamp("20170101", tz="US/Eastern")] * 4, name="value"
662+
)
663+
tm.assert_series_equal(result, expected)

pandas/tests/groupby/transform/test_transform.py

+8
Original file line numberDiff line numberDiff line change
@@ -1289,3 +1289,11 @@ def test_transform_cumcount():
12891289

12901290
result = grp.transform("cumcount")
12911291
tm.assert_series_equal(result, expected)
1292+
1293+
1294+
def test_null_group_lambda_self():
1295+
# GH 17093
1296+
df = DataFrame({"A": [1, np.nan], "B": [1, 1]})
1297+
result = df.groupby("A").transform(lambda x: x)
1298+
expected = DataFrame([1], columns=["B"])
1299+
tm.assert_frame_equal(result, expected)

pandas/tests/io/parser/test_read_fwf.py

+9
Original file line numberDiff line numberDiff line change
@@ -853,3 +853,12 @@ def test_len_colspecs_len_names_with_index_col(
853853
index_col=index_col,
854854
)
855855
tm.assert_frame_equal(result, expected)
856+
857+
858+
def test_colspecs_with_comment():
859+
# GH 14135
860+
result = read_fwf(
861+
StringIO("#\nA1K\n"), colspecs=[(1, 2), (2, 3)], comment="#", header=None
862+
)
863+
expected = DataFrame([[1, "K"]], columns=[0, 1])
864+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)