diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 7fe921571ee2e..da930ab4d7423 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -1837,3 +1837,11 @@ def test_arithemetic_multiindex_align(): ) result = df1 - df2 tm.assert_frame_equal(result, expected) + + +def test_bool_frame_mult_float(): + # GH 18549 + 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) diff --git a/pandas/tests/groupby/test_filters.py b/pandas/tests/groupby/test_filters.py index 995fd58a84cbd..b40514568452c 100644 --- a/pandas/tests/groupby/test_filters.py +++ b/pandas/tests/groupby/test_filters.py @@ -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) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 0c20622311e1f..772aa97c47233 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -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 diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 8c79bafa2f888..c1a096ed06efc 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -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( diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index 219c94b5a895d..10c8ccae67fb2 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -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 diff --git a/pandas/tests/tseries/offsets/test_custom_business_hour.py b/pandas/tests/tseries/offsets/test_custom_business_hour.py index 07270008adbd2..c2b4e3c343c11 100644 --- a/pandas/tests/tseries/offsets/test_custom_business_hour.py +++ b/pandas/tests/tseries/offsets/test_custom_business_hour.py @@ -19,6 +19,8 @@ assert_offset_equal, ) +from pandas.tseries.holiday import USFederalHolidayCalendar + class TestCustomBusinessHour(Base): _offset = CustomBusinessHour @@ -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