Skip to content

Commit fd38824

Browse files
authored
TST: Old Issues (#41674)
1 parent d662e97 commit fd38824

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed

pandas/tests/frame/test_arithmetic.py

+8
Original file line numberDiff line numberDiff line change
@@ -1837,3 +1837,11 @@ def test_arithemetic_multiindex_align():
18371837
)
18381838
result = df1 - df2
18391839
tm.assert_frame_equal(result, expected)
1840+
1841+
1842+
def test_bool_frame_mult_float():
1843+
# GH 18549
1844+
df = DataFrame(True, list("ab"), list("cd"))
1845+
result = df * 1.0
1846+
expected = DataFrame(np.ones((2, 2)), list("ab"), list("cd"))
1847+
tm.assert_frame_equal(result, expected)

pandas/tests/groupby/test_filters.py

+13
Original file line numberDiff line numberDiff line change
@@ -599,3 +599,16 @@ def test_filter_dropna_with_empty_groups():
599599
result_true = groupped.filter(lambda x: x.mean() > 1, dropna=True)
600600
expected_true = Series(index=pd.Index([], dtype=int), dtype=np.float64)
601601
tm.assert_series_equal(result_true, expected_true)
602+
603+
604+
def test_filter_consistent_result_before_after_agg_func():
605+
# GH 17091
606+
df = DataFrame({"data": range(6), "key": list("ABCABC")})
607+
grouper = df.groupby("key")
608+
result = grouper.filter(lambda x: True)
609+
expected = DataFrame({"data": range(6), "key": list("ABCABC")})
610+
tm.assert_frame_equal(result, expected)
611+
612+
grouper.sum()
613+
result = grouper.filter(lambda x: True)
614+
tm.assert_frame_equal(result, expected)

pandas/tests/indexing/test_indexing.py

+7
Original file line numberDiff line numberDiff line change
@@ -977,3 +977,10 @@ def test_extension_array_cross_section_converts():
977977

978978
result = df.iloc[0]
979979
tm.assert_series_equal(result, expected)
980+
981+
982+
def test_getitem_object_index_float_string():
983+
# GH 17286
984+
s = Series([1] * 4, index=Index(["a", "b", "c", 1.0]))
985+
assert s["a"] == 1
986+
assert s[1.0] == 1

pandas/tests/indexing/test_loc.py

+13
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,19 @@ def test_loc_getitem_slice_datetime_objs_with_datetimeindex(self):
15651565
result = ser.loc[datetime(1900, 1, 1) : datetime(2100, 1, 1)]
15661566
tm.assert_series_equal(result, ser)
15671567

1568+
def test_loc_getitem_datetime_string_with_datetimeindex(self):
1569+
# GH 16710
1570+
df = DataFrame(
1571+
{"a": range(10), "b": range(10)},
1572+
index=date_range("2010-01-01", "2010-01-10"),
1573+
)
1574+
result = df.loc[["2010-01-01", "2010-01-05"], ["a", "b"]]
1575+
expected = DataFrame(
1576+
{"a": [0, 4], "b": [0, 4]},
1577+
index=DatetimeIndex(["2010-01-01", "2010-01-05"]),
1578+
)
1579+
tm.assert_frame_equal(result, expected)
1580+
15681581
def test_loc_getitem_sorted_index_level_with_duplicates(self):
15691582
# GH#4516 sorting a MultiIndex with duplicates and multiple dtypes
15701583
mi = MultiIndex.from_tuples(

pandas/tests/io/formats/test_to_latex.py

+38
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,44 @@ def test_to_latex_non_string_index(self):
13931393
)
13941394
assert result == expected
13951395

1396+
def test_to_latex_multiindex_multirow(self):
1397+
# GH 16719
1398+
mi = pd.MultiIndex.from_product(
1399+
[[0.0, 1.0], [3.0, 2.0, 1.0], ["0", "1"]], names=["i", "val0", "val1"]
1400+
)
1401+
df = DataFrame(index=mi)
1402+
result = df.to_latex(multirow=True, escape=False)
1403+
expected = _dedent(
1404+
r"""
1405+
\begin{tabular}{lll}
1406+
\toprule
1407+
& & \\
1408+
i & val0 & val1 \\
1409+
\midrule
1410+
\multirow{6}{*}{0.0} & \multirow{2}{*}{3.0} & 0 \\
1411+
& & 1 \\
1412+
\cline{2-3}
1413+
& \multirow{2}{*}{2.0} & 0 \\
1414+
& & 1 \\
1415+
\cline{2-3}
1416+
& \multirow{2}{*}{1.0} & 0 \\
1417+
& & 1 \\
1418+
\cline{1-3}
1419+
\cline{2-3}
1420+
\multirow{6}{*}{1.0} & \multirow{2}{*}{3.0} & 0 \\
1421+
& & 1 \\
1422+
\cline{2-3}
1423+
& \multirow{2}{*}{2.0} & 0 \\
1424+
& & 1 \\
1425+
\cline{2-3}
1426+
& \multirow{2}{*}{1.0} & 0 \\
1427+
& & 1 \\
1428+
\bottomrule
1429+
\end{tabular}
1430+
"""
1431+
)
1432+
assert result == expected
1433+
13961434

13971435
class TestTableBuilder:
13981436
@pytest.fixture

pandas/tests/tseries/offsets/test_custom_business_hour.py

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
assert_offset_equal,
2020
)
2121

22+
from pandas.tseries.holiday import USFederalHolidayCalendar
23+
2224

2325
class TestCustomBusinessHour(Base):
2426
_offset = CustomBusinessHour
@@ -298,3 +300,11 @@ def test_apply_nanoseconds(self, nano_case):
298300
offset, cases = nano_case
299301
for base, expected in cases.items():
300302
assert_offset_equal(offset, base, expected)
303+
304+
def test_us_federal_holiday_with_datetime(self):
305+
# GH 16867
306+
bhour_us = CustomBusinessHour(calendar=USFederalHolidayCalendar())
307+
t0 = datetime(2014, 1, 17, 15)
308+
result = t0 + bhour_us * 8
309+
expected = Timestamp("2014-01-21 15:00:00")
310+
assert result == expected

0 commit comments

Comments
 (0)