Skip to content

Commit f25ed6f

Browse files
authored
misplaced DataFrame.join test (#32375)
1 parent a1f9ae2 commit f25ed6f

File tree

3 files changed

+78
-73
lines changed

3 files changed

+78
-73
lines changed

pandas/tests/frame/test_combine_concat.py

+1-72
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pandas._testing as tm
99

1010

11-
class TestDataFrameConcatCommon:
11+
class TestDataFrameConcat:
1212
def test_concat_multiple_frames_dtypes(self):
1313

1414
# GH 2759
@@ -107,77 +107,6 @@ def test_concat_tuple_keys(self):
107107
)
108108
tm.assert_frame_equal(results, expected)
109109

110-
def test_join_str_datetime(self):
111-
str_dates = ["20120209", "20120222"]
112-
dt_dates = [datetime(2012, 2, 9), datetime(2012, 2, 22)]
113-
114-
A = DataFrame(str_dates, index=range(2), columns=["aa"])
115-
C = DataFrame([[1, 2], [3, 4]], index=str_dates, columns=dt_dates)
116-
117-
tst = A.join(C, on="aa")
118-
119-
assert len(tst.columns) == 3
120-
121-
def test_join_multiindex_leftright(self):
122-
# GH 10741
123-
df1 = pd.DataFrame(
124-
[
125-
["a", "x", 0.471780],
126-
["a", "y", 0.774908],
127-
["a", "z", 0.563634],
128-
["b", "x", -0.353756],
129-
["b", "y", 0.368062],
130-
["b", "z", -1.721840],
131-
["c", "x", 1],
132-
["c", "y", 2],
133-
["c", "z", 3],
134-
],
135-
columns=["first", "second", "value1"],
136-
).set_index(["first", "second"])
137-
138-
df2 = pd.DataFrame(
139-
[["a", 10], ["b", 20]], columns=["first", "value2"]
140-
).set_index(["first"])
141-
142-
exp = pd.DataFrame(
143-
[
144-
[0.471780, 10],
145-
[0.774908, 10],
146-
[0.563634, 10],
147-
[-0.353756, 20],
148-
[0.368062, 20],
149-
[-1.721840, 20],
150-
[1.000000, np.nan],
151-
[2.000000, np.nan],
152-
[3.000000, np.nan],
153-
],
154-
index=df1.index,
155-
columns=["value1", "value2"],
156-
)
157-
158-
# these must be the same results (but columns are flipped)
159-
tm.assert_frame_equal(df1.join(df2, how="left"), exp)
160-
tm.assert_frame_equal(df2.join(df1, how="right"), exp[["value2", "value1"]])
161-
162-
exp_idx = pd.MultiIndex.from_product(
163-
[["a", "b"], ["x", "y", "z"]], names=["first", "second"]
164-
)
165-
exp = pd.DataFrame(
166-
[
167-
[0.471780, 10],
168-
[0.774908, 10],
169-
[0.563634, 10],
170-
[-0.353756, 20],
171-
[0.368062, 20],
172-
[-1.721840, 20],
173-
],
174-
index=exp_idx,
175-
columns=["value1", "value2"],
176-
)
177-
178-
tm.assert_frame_equal(df1.join(df2, how="right"), exp)
179-
tm.assert_frame_equal(df2.join(df1, how="left"), exp[["value2", "value1"]])
180-
181110
def test_concat_named_keys(self):
182111
# GH 14252
183112
df = pd.DataFrame({"foo": [1, 2], "bar": [0.1, 0.2]})

pandas/tests/frame/test_join.py

+76
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from datetime import datetime
2+
13
import numpy as np
24
import pytest
35

6+
import pandas as pd
47
from pandas import DataFrame, Index, period_range
58
import pandas._testing as tm
69

@@ -216,3 +219,76 @@ def test_suppress_future_warning_with_sort_kw(sort_kw):
216219
with tm.assert_produces_warning(None, check_stacklevel=False):
217220
result = a.join([b, c], how="outer", sort=sort_kw)
218221
tm.assert_frame_equal(result, expected)
222+
223+
224+
class TestDataFrameJoin:
225+
def test_join_str_datetime(self):
226+
str_dates = ["20120209", "20120222"]
227+
dt_dates = [datetime(2012, 2, 9), datetime(2012, 2, 22)]
228+
229+
A = DataFrame(str_dates, index=range(2), columns=["aa"])
230+
C = DataFrame([[1, 2], [3, 4]], index=str_dates, columns=dt_dates)
231+
232+
tst = A.join(C, on="aa")
233+
234+
assert len(tst.columns) == 3
235+
236+
def test_join_multiindex_leftright(self):
237+
# GH 10741
238+
df1 = pd.DataFrame(
239+
[
240+
["a", "x", 0.471780],
241+
["a", "y", 0.774908],
242+
["a", "z", 0.563634],
243+
["b", "x", -0.353756],
244+
["b", "y", 0.368062],
245+
["b", "z", -1.721840],
246+
["c", "x", 1],
247+
["c", "y", 2],
248+
["c", "z", 3],
249+
],
250+
columns=["first", "second", "value1"],
251+
).set_index(["first", "second"])
252+
253+
df2 = pd.DataFrame(
254+
[["a", 10], ["b", 20]], columns=["first", "value2"]
255+
).set_index(["first"])
256+
257+
exp = pd.DataFrame(
258+
[
259+
[0.471780, 10],
260+
[0.774908, 10],
261+
[0.563634, 10],
262+
[-0.353756, 20],
263+
[0.368062, 20],
264+
[-1.721840, 20],
265+
[1.000000, np.nan],
266+
[2.000000, np.nan],
267+
[3.000000, np.nan],
268+
],
269+
index=df1.index,
270+
columns=["value1", "value2"],
271+
)
272+
273+
# these must be the same results (but columns are flipped)
274+
tm.assert_frame_equal(df1.join(df2, how="left"), exp)
275+
tm.assert_frame_equal(df2.join(df1, how="right"), exp[["value2", "value1"]])
276+
277+
exp_idx = pd.MultiIndex.from_product(
278+
[["a", "b"], ["x", "y", "z"]], names=["first", "second"]
279+
)
280+
exp = pd.DataFrame(
281+
[
282+
[0.471780, 10],
283+
[0.774908, 10],
284+
[0.563634, 10],
285+
[-0.353756, 20],
286+
[0.368062, 20],
287+
[-1.721840, 20],
288+
],
289+
index=exp_idx,
290+
columns=["value1", "value2"],
291+
)
292+
293+
tm.assert_frame_equal(df1.join(df2, how="right"), exp)
294+
tm.assert_frame_equal(df2.join(df1, how="left"), exp[["value2", "value1"]])

pandas/tests/series/test_combine_concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pandas import Series
66

77

8-
class TestSeriesCombine:
8+
class TestSeriesConcat:
99
@pytest.mark.parametrize(
1010
"dtype", ["float64", "int8", "uint8", "bool", "m8[ns]", "M8[ns]"]
1111
)

0 commit comments

Comments
 (0)