Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,3 +1837,10 @@ def test_arithemetic_multiindex_align():
)
result = df1 - df2
tm.assert_frame_equal(result, expected)


def test_bool_frame_mult_float():
# GH 18549
result = DataFrame(True, list("ab"), list("cd")) * 1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, I think the result assignment should be just the op under test

Suggested change
result = DataFrame(True, list("ab"), list("cd")) * 1.0
df = DataFrame(True, list("ab"), list("cd"))
result = df * 1.0

expected = DataFrame(np.ones((2, 2)), list("ab"), list("cd"))
tm.assert_frame_equal(result, expected)
13 changes: 13 additions & 0 deletions pandas/tests/groupby/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,3 +599,16 @@ def test_filter_dropna_with_empty_groups():
result_true = groupped.filter(lambda x: x.mean() > 1, dropna=True)
expected_true = Series(index=pd.Index([], dtype=int), dtype=np.float64)
tm.assert_series_equal(result_true, expected_true)


def test_filter_consistent_result_before_after_agg_func():
# GH 17091
df = DataFrame({"data": range(6), "key": list("ABCABC")})
grouper = df.groupby("key")
result = grouper.filter(lambda x: True)
expected = DataFrame({"data": range(6), "key": list("ABCABC")})
tm.assert_frame_equal(result, expected)

grouper.sum()
result = grouper.filter(lambda x: True)
tm.assert_frame_equal(result, expected)
7 changes: 7 additions & 0 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,3 +977,10 @@ def test_extension_array_cross_section_converts():

result = df.iloc[0]
tm.assert_series_equal(result, expected)


def test_getitem_object_index_float_string():
# GH 17286
s = Series([1] * 4, index=Index(["a", "b", "c", 1.0]))
assert s["a"] == 1
assert s[1.0] == 1
13 changes: 13 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,19 @@ def test_loc_getitem_slice_datetime_objs_with_datetimeindex(self):
result = ser.loc[datetime(1900, 1, 1) : datetime(2100, 1, 1)]
tm.assert_series_equal(result, ser)

def test_loc_getitem_datetime_string_with_datetimeindex(self):
# GH 16710
df = DataFrame(
{"a": range(10), "b": range(10)},
index=date_range("2010-01-01", "2010-01-10"),
)
result = df.loc[["2010-01-01", "2010-01-05"], ["a", "b"]]
expected = DataFrame(
{"a": [0, 4], "b": [0, 4]},
index=DatetimeIndex(["2010-01-01", "2010-01-05"]),
)
tm.assert_frame_equal(result, expected)

def test_loc_getitem_sorted_index_level_with_duplicates(self):
# GH#4516 sorting a MultiIndex with duplicates and multiple dtypes
mi = MultiIndex.from_tuples(
Expand Down
38 changes: 38 additions & 0 deletions pandas/tests/io/formats/test_to_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,44 @@ def test_to_latex_non_string_index(self):
)
assert result == expected

def test_to_latex_multiindex_multirow(self):
# GH 16719
mi = pd.MultiIndex.from_product(
[[0.0, 1.0], [3.0, 2.0, 1.0], ["0", "1"]], names=["i", "val0", "val1"]
)
df = DataFrame(index=mi)
result = df.to_latex(multirow=True, escape=False)
expected = _dedent(
r"""
\begin{tabular}{lll}
\toprule
& & \\
i & val0 & val1 \\
\midrule
\multirow{6}{*}{0.0} & \multirow{2}{*}{3.0} & 0 \\
& & 1 \\
\cline{2-3}
& \multirow{2}{*}{2.0} & 0 \\
& & 1 \\
\cline{2-3}
& \multirow{2}{*}{1.0} & 0 \\
& & 1 \\
\cline{1-3}
\cline{2-3}
\multirow{6}{*}{1.0} & \multirow{2}{*}{3.0} & 0 \\
& & 1 \\
\cline{2-3}
& \multirow{2}{*}{2.0} & 0 \\
& & 1 \\
\cline{2-3}
& \multirow{2}{*}{1.0} & 0 \\
& & 1 \\
\bottomrule
\end{tabular}
"""
)
assert result == expected


class TestTableBuilder:
@pytest.fixture
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/tseries/offsets/test_custom_business_hour.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
assert_offset_equal,
)

from pandas.tseries.holiday import USFederalHolidayCalendar


class TestCustomBusinessHour(Base):
_offset = CustomBusinessHour
Expand Down Expand Up @@ -298,3 +300,11 @@ def test_apply_nanoseconds(self, nano_case):
offset, cases = nano_case
for base, expected in cases.items():
assert_offset_equal(offset, base, expected)

def test_us_federal_holiday_with_datetime(self):
# GH 16867
bhour_us = CustomBusinessHour(calendar=USFederalHolidayCalendar())
t0 = datetime(2014, 1, 17, 15)
result = t0 + bhour_us * 8
expected = Timestamp("2014-01-21 15:00:00")
assert result == expected