Skip to content

TST: Add tests for fixed issues #30444

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 5 commits into from
Dec 26, 2019
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
26 changes: 26 additions & 0 deletions pandas/tests/indexing/multiindex/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,29 @@ def test_loc_setitem_single_column_slice():
df.loc[:, "B"] = np.arange(4)
expected.iloc[:, 2] = np.arange(4)
tm.assert_frame_equal(df, expected)


def test_loc_nan_multiindex():
# GH 5286
tups = [
("Good Things", "C", np.nan),
("Good Things", "R", np.nan),
("Bad Things", "C", np.nan),
("Bad Things", "T", np.nan),
("Okay Things", "N", "B"),
("Okay Things", "N", "D"),
("Okay Things", "B", np.nan),
("Okay Things", "D", np.nan),
]
df = DataFrame(
np.ones((8, 4)),
columns=Index(["d1", "d2", "d3", "d4"]),
index=MultiIndex.from_tuples(tups, names=["u1", "u2", "u3"]),
)
result = df.loc["Good Things"].loc["C"]
expected = DataFrame(
np.ones((1, 4)),
index=Index([np.nan], dtype="object", name="u3"),
columns=Index(["d1", "d2", "d3", "d4"], dtype="object"),
)
tm.assert_frame_equal(result, expected)
17 changes: 17 additions & 0 deletions pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,3 +1564,20 @@ def test_get_timestamp_range_edges(first, last, offset, exp_first, exp_last):
result = _get_timestamp_range_edges(first, last, offset)
expected = (exp_first, exp_last)
assert result == expected


def test_resample_apply_product():
# GH 5586
index = date_range(start="2012-01-31", freq="M", periods=12)

ts = Series(range(12), index=index)
df = DataFrame(dict(A=ts, B=ts + 2))
result = df.resample("Q").apply(np.product)
expected = DataFrame(
np.array([[0, 24], [60, 210], [336, 720], [990, 1716]], dtype=np.int64),
index=DatetimeIndex(
["2012-03-31", "2012-06-30", "2012-09-30", "2012-12-31"], freq="Q-DEC"
),
columns=["A", "B"],
)
tm.assert_frame_equal(result, expected)
29 changes: 29 additions & 0 deletions pandas/tests/reshape/merge/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,35 @@ def test_join_on_tz_aware_datetimeindex(self):
expected["vals_2"] = pd.Series([np.nan] * 2 + list("tuv"), dtype=object)
tm.assert_frame_equal(result, expected)

def test_join_datetime_string(self):
# GH 5647
dfa = DataFrame(
[
["2012-08-02", "L", 10],
["2012-08-02", "J", 15],
["2013-04-06", "L", 20],
["2013-04-06", "J", 25],
],
columns=["x", "y", "a"],
)
dfa["x"] = pd.to_datetime(dfa["x"])
dfb = DataFrame(
[["2012-08-02", "J", 1], ["2013-04-06", "L", 2]],
columns=["x", "y", "z"],
index=[2, 4],
)
dfb["x"] = pd.to_datetime(dfb["x"])
result = dfb.join(dfa.set_index(["x", "y"]), on=["x", "y"])
expected = DataFrame(
[
[pd.Timestamp("2012-08-02 00:00:00"), "J", 1, 15],
[pd.Timestamp("2013-04-06 00:00:00"), "L", 2, 20],
],
index=[2, 4],
columns=["x", "y", "z", "a"],
)
tm.assert_frame_equal(result, expected)


def _check_join(left, right, result, join_col, how="left", lsuffix="_x", rsuffix="_y"):

Expand Down