Skip to content
Prev Previous commit
Next Next commit
test fixes
  • Loading branch information
PCerles committed Nov 2, 2020
commit a70c0ff3671e69469ea7778e3885b48ac024d9ba
57 changes: 28 additions & 29 deletions pandas/tests/reshape/merge/test_multi.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import numpy as np
import pytest

from numpy.random import randn
import pandas as pd
from pandas import DataFrame, Index, MultiIndex, Series
import pandas._testing as tm
from pandas.core.reshape.concat import concat
from pandas.core.reshape.merge import merge
import pytest


@pytest.fixture
Expand Down Expand Up @@ -457,33 +457,6 @@ def test_merge_na_keys(self):

tm.assert_frame_equal(result, expected)

def test_merge_datetime_index_empty_df(self):

date = np.array(
[pd.Timestamp("1950-01-01"), pd.Timestamp("1950-01-02")],
dtype=np.datetime64,
)
panel = np.array(["A", "B"], dtype=object)
data = np.array([1.5, 1.5], dtype=np.float64)

frame = DataFrame({"date": date, "panel": panel, "data": data}).set_index(
["date", "panel"]
)
other = DataFrame(columns=["date", "panel", "state"]).set_index(
["date", "panel"]
)

state = np.array([np.nan, np.nan], dtype=object)

expected = DataFrame(
{"date": date, "panel": panel, "data": data, "state": state}
)
expected = expected.set_index(["date", "panel"])

result = frame.merge(other, how="left", on=["date", "panel"])

tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("klass", [None, np.asarray, Series, Index])
def test_merge_datetime_index(self, klass):
# see gh-19038
Expand Down Expand Up @@ -863,3 +836,29 @@ def test_join_multi_wrong_order(self):
)

tm.assert_frame_equal(result, expected)


def test_merge_datetime_index_empty_df():

frame = DataFrame(
{
"date": [pd.Timestamp("1950-01-01"), pd.Timestamp("1950-01-02")],
"panel": ["A", "B"],
"data": [1.5, 1.5],
}
).set_index(["date", "panel"])
other = DataFrame(columns=["date", "panel", "state"]).set_index(["date", "panel"])

expected = DataFrame(
{
"date": [pd.Timestamp("1950-01-01"), pd.Timestamp("1950-01-02")],
"panel": ["A", "B"],
"data": [1.5, 1.5],
"state": [None, None],
}
)
expected = expected.set_index(["date", "panel"])

result = frame.merge(other, how="left", on=["date", "panel"])
Copy link
Contributor

Choose a reason for hiding this comment

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

can u test the other cases from the OP that they give the correct results


tm.assert_frame_equal(result, expected)