From cba4abb9bff877573b4fa3f91be117f44a35b690 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Thu, 30 Jan 2020 12:55:52 +0000 Subject: [PATCH] :pencil: add whatsnew entry to v1.0.1 --- doc/source/whatsnew/v1.0.0.rst | 1 - doc/source/whatsnew/v1.0.1.rst | 32 ++++++++++++++++++++++ pandas/tests/reshape/merge/test_merge.py | 34 ++++++++++++------------ 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 939710bf4d45a3..00dc3fdb28f26d 100755 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -1247,7 +1247,6 @@ Reshaping - Bug in :func:`merge_asof` merging on a tz-aware ``left_index`` and ``right_on`` a tz-aware column (:issue:`29864`) - Improved error message and docstring in :func:`cut` and :func:`qcut` when `labels=True` (:issue:`13318`) - Bug in missing `fill_na` parameter to :meth:`DataFrame.unstack` with list of levels (:issue:`30740`) -- :meth:`DataFrame.merge` now preserves right frame's row order when executing a right merge (:issue:`27453`) Sparse ^^^^^^ diff --git a/doc/source/whatsnew/v1.0.1.rst b/doc/source/whatsnew/v1.0.1.rst index b84448e3bf8960..5eec8c57bb15b9 100644 --- a/doc/source/whatsnew/v1.0.1.rst +++ b/doc/source/whatsnew/v1.0.1.rst @@ -10,6 +10,38 @@ including other versions of pandas. .. --------------------------------------------------------------------------- +.. _whatsnew_101.api_breaking: + +Backwards incompatible API changes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:meth:`DataFrame.merge` preserves right frame's row order +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +:meth:`DataFrame.merge` now preserves right frame's row order when executing a right merge (:issue:`27453`) + +.. ipython:: python + + left_df = pd.DataFrame({'animal': ['dog', 'pig'], 'max_speed': [40, 11]}) + right_df = pd.DataFrame({'animal': ['quetzal', 'pig'], 'max_speed': [80, 11]}) + left_df + right_df + +*pandas 1.0.0* + +.. code-block:: python + + >>> left_df.merge(right_df, on=['animal', 'max_speed'], how="right") + animal max_speed + 0 pig 11 + 1 quetzal 80 + +*pandas 1.0.1* + +.. ipython:: python + + left_df.merge(right_df, on=['animal', 'max_speed'], how="right") + +.. --------------------------------------------------------------------------- .. _whatsnew_101.bug_fixes: diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index f500d6811256a0..b356a905947025 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -2174,25 +2174,25 @@ def test_merge_datetime_upcast_dtype(): @pytest.mark.parametrize("how", ["left", "right"]) def test_merge_preserves_row_order(how): # GH 27453 - population = [ - ("Jenn", "Jamaica", 3), - ("Beth", "Bulgaria", 7), - ("Carl", "Canada", 30), - ] - columns = ["name", "country", "population"] - population_df = DataFrame(population, columns=columns) + population_df = DataFrame( + { + "name": ["Jenn", "Beth", "Carl"], + "country": ["Jamaica", "Bulgaria", "Canada"], + "population": [3, 7, 30], + } + ) - people = [("Abe", "America"), ("Beth", "Bulgaria"), ("Carl", "Canada")] - columns = ["name", "country"] - people_df = DataFrame(people, columns=columns) + people_df = DataFrame( + {"name": ["Abe", "Beth", "Carl"], "country": ["America", "Bulgaria", "Canada"]} + ) - expected_data = [ - ("Abe", "America", np.nan), - ("Beth", "Bulgaria", 7), - ("Carl", "Canada", 30), - ] - expected_cols = ["name", "country", "population"] - expected = DataFrame(expected_data, columns=expected_cols) + expected = DataFrame( + { + "name": ["Abe", "Beth", "Carl"], + "country": ["America", "Bulgaria", "Canada"], + "population": [np.nan, 7, 30], + } + ) if how == "right": left_df, right_df = population_df, people_df