Skip to content

TST: Old issues #44245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pandas/tests/apply/test_series_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,3 +878,15 @@ def test_apply_dictlike_transformer(string_series, ops):
expected.name = string_series.name
result = string_series.apply(ops)
tm.assert_series_equal(result, expected)


def test_apply_retains_column_name():
# GH 16380
df = DataFrame({"x": range(3)}, Index(range(3), name="x"))
result = df.x.apply(lambda x: Series(range(x + 1), Index(range(x + 1), name="y")))
expected = DataFrame(
[[0.0, np.nan, np.nan], [0.0, 1.0, np.nan], [0.0, 1.0, 2.0]],
columns=Index(range(3), name="y"),
index=Index(range(3), name="x"),
)
tm.assert_frame_equal(result, expected)
10 changes: 10 additions & 0 deletions pandas/tests/arithmetic/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ def test_categorical_nan_equality(self):
expected = Series([True, True, True, False])
result = cat == cat
tm.assert_series_equal(result, expected)

def test_categorical_tuple_equality(self):
# GH 18050
ser = Series([(0, 0), (0, 1), (0, 0), (1, 0), (1, 1)])
expected = Series([True, False, True, False, False])
result = ser == (0, 0)
tm.assert_series_equal(result, expected)

result = ser.astype("category") == (0, 0)
tm.assert_series_equal(result, expected)
18 changes: 18 additions & 0 deletions pandas/tests/frame/test_stack_unstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,3 +2081,21 @@ def test_unstack_categorical_columns(self):
)
expected.columns = MultiIndex.from_tuples([("cat", 0), ("cat", 1)])
tm.assert_frame_equal(result, expected)

def test_stack_unsorted(self):
# GH 16925
PAE = ["ITA", "FRA"]
VAR = ["A1", "A2"]
TYP = ["CRT", "DBT", "NET"]
MI = MultiIndex.from_product([PAE, VAR, TYP], names=["PAE", "VAR", "TYP"])

V = list(range(len(MI)))
DF = DataFrame(data=V, index=MI, columns=["VALUE"])

DF = DF.unstack(["VAR", "TYP"])
DF.columns = DF.columns.droplevel(0)
DF.loc[:, ("A0", "NET")] = 9999

result = DF.stack(["VAR", "TYP"]).sort_index()
expected = DF.sort_index(axis=1).stack(["VAR", "TYP"]).sort_index()
tm.assert_series_equal(result, expected)
10 changes: 10 additions & 0 deletions pandas/tests/groupby/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,3 +1155,13 @@ def test_groupby_sum_below_mincount_nullable_integer():
result = grouped.sum(min_count=2)
expected = DataFrame({"b": [pd.NA] * 3, "c": [pd.NA] * 3}, dtype="Int64", index=idx)
tm.assert_frame_equal(result, expected)


def test_mean_on_timedelta():
# GH 17382
df = DataFrame({"time": pd.to_timedelta(range(10)), "cat": ["A", "B"] * 5})
result = df.groupby("cat")["time"].mean()
expected = Series(
pd.to_timedelta([4, 5]), name="time", index=Index(["A", "B"], name="cat")
)
tm.assert_series_equal(result, expected)
13 changes: 13 additions & 0 deletions pandas/tests/groupby/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,16 @@ def test_groupby_axis0_cummax_axis1():
expected = df[[0, 1]].astype(np.float64)
expected[2] = expected[1]
tm.assert_frame_equal(cmax, expected)


def test_non_unique_index():
# GH 16577
df = DataFrame(
{"A": [1.0, 2.0, 3.0, np.nan], "value": 1.0},
index=[pd.Timestamp("20170101", tz="US/Eastern")] * 4,
)
result = df.groupby([df.index, "A"]).value.rank(ascending=True, pct=True)
expected = Series(
[1.0] * 4, index=[pd.Timestamp("20170101", tz="US/Eastern")] * 4, name="value"
)
tm.assert_series_equal(result, expected)
8 changes: 8 additions & 0 deletions pandas/tests/groupby/transform/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,3 +1289,11 @@ def test_transform_cumcount():

result = grp.transform("cumcount")
tm.assert_series_equal(result, expected)


def test_null_group_lambda_self():
# GH 17093
df = DataFrame({"A": [1, np.nan], "B": [1, 1]})
result = df.groupby("A").transform(lambda x: x)
expected = DataFrame([1], columns=["B"])
tm.assert_frame_equal(result, expected)
9 changes: 9 additions & 0 deletions pandas/tests/io/parser/test_read_fwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,3 +853,12 @@ def test_len_colspecs_len_names_with_index_col(
index_col=index_col,
)
tm.assert_frame_equal(result, expected)


def test_colspecs_with_comment():
# GH 14135
result = read_fwf(
StringIO("#\nA1K\n"), colspecs=[(1, 2), (2, 3)], comment="#", header=None
)
expected = DataFrame([[1, "K"]], columns=[0, 1])
tm.assert_frame_equal(result, expected)