Skip to content

Commit 5f9fb1d

Browse files
authored
test_combine.py (#32253)
1 parent c5e3e25 commit 5f9fb1d

File tree

3 files changed

+47
-40
lines changed

3 files changed

+47
-40
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import numpy as np
2+
import pytest
3+
4+
import pandas as pd
5+
import pandas._testing as tm
6+
7+
8+
class TestCombine:
9+
@pytest.mark.parametrize(
10+
"data",
11+
[
12+
pd.date_range("2000", periods=4),
13+
pd.date_range("2000", periods=4, tz="US/Central"),
14+
pd.period_range("2000", periods=4),
15+
pd.timedelta_range(0, periods=4),
16+
],
17+
)
18+
def test_combine_datetlike_udf(self, data):
19+
# GH#23079
20+
df = pd.DataFrame({"A": data})
21+
other = df.copy()
22+
df.iloc[1, 0] = None
23+
24+
def combiner(a, b):
25+
return b
26+
27+
result = df.combine(other, combiner)
28+
tm.assert_frame_equal(result, other)
29+
30+
def test_combine_generic(self, float_frame):
31+
df1 = float_frame
32+
df2 = float_frame.loc[float_frame.index[:-5], ["A", "B", "C"]]
33+
34+
combined = df1.combine(df2, np.add)
35+
combined2 = df2.combine(df1, np.add)
36+
assert combined["D"].isna().all()
37+
assert combined2["D"].isna().all()
38+
39+
chunk = combined.loc[combined.index[:-5], ["A", "B", "C"]]
40+
chunk2 = combined2.loc[combined2.index[:-5], ["A", "B", "C"]]
41+
42+
exp = (
43+
float_frame.loc[float_frame.index[:-5], ["A", "B", "C"]].reindex_like(chunk)
44+
* 2
45+
)
46+
tm.assert_frame_equal(chunk, exp)
47+
tm.assert_frame_equal(chunk2, exp)

pandas/tests/frame/test_combine_concat.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@ def test_concat_multiple_frames_dtypes(self):
2121
)
2222
tm.assert_series_equal(results, expected)
2323

24-
@pytest.mark.parametrize(
25-
"data",
26-
[
27-
pd.date_range("2000", periods=4),
28-
pd.date_range("2000", periods=4, tz="US/Central"),
29-
pd.period_range("2000", periods=4),
30-
pd.timedelta_range(0, periods=4),
31-
],
32-
)
33-
def test_combine_datetlike_udf(self, data):
34-
# https://github.com/pandas-dev/pandas/issues/23079
35-
df = pd.DataFrame({"A": data})
36-
other = df.copy()
37-
df.iloc[1, 0] = None
38-
39-
def combiner(a, b):
40-
return b
41-
42-
result = df.combine(other, combiner)
43-
tm.assert_frame_equal(result, other)
44-
4524
def test_concat_multiple_tzs(self):
4625
# GH 12467
4726
# combining datetime tz-aware and naive DataFrames

pandas/tests/frame/test_operators.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -685,25 +685,6 @@ def test_boolean_comparison(self):
685685
with pytest.raises(ValueError, match=msg1d):
686686
result = df == tup
687687

688-
def test_combine_generic(self, float_frame):
689-
df1 = float_frame
690-
df2 = float_frame.loc[float_frame.index[:-5], ["A", "B", "C"]]
691-
692-
combined = df1.combine(df2, np.add)
693-
combined2 = df2.combine(df1, np.add)
694-
assert combined["D"].isna().all()
695-
assert combined2["D"].isna().all()
696-
697-
chunk = combined.loc[combined.index[:-5], ["A", "B", "C"]]
698-
chunk2 = combined2.loc[combined2.index[:-5], ["A", "B", "C"]]
699-
700-
exp = (
701-
float_frame.loc[float_frame.index[:-5], ["A", "B", "C"]].reindex_like(chunk)
702-
* 2
703-
)
704-
tm.assert_frame_equal(chunk, exp)
705-
tm.assert_frame_equal(chunk2, exp)
706-
707688
def test_inplace_ops_alignment(self):
708689

709690
# inplace ops / ops alignment

0 commit comments

Comments
 (0)