Skip to content

Commit ddd77dc

Browse files
authored
TST: Add regression tests for old issues (#45095)
1 parent 3aed81c commit ddd77dc

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

pandas/tests/frame/methods/test_combine_first.py

+9
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,12 @@ def test_combine_first_duplicates_rows_for_nan_index_values():
517517
)
518518
combined = df1.combine_first(df2)
519519
tm.assert_frame_equal(combined, expected)
520+
521+
522+
def test_combine_first_int64_not_cast_to_float64():
523+
# GH 28613
524+
df_1 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
525+
df_2 = DataFrame({"A": [1, 20, 30], "B": [40, 50, 60], "C": [12, 34, 65]})
526+
result = df_1.combine_first(df_2)
527+
expected = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [12, 34, 65]})
528+
tm.assert_frame_equal(result, expected)

pandas/tests/frame/methods/test_reset_index.py

+15
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
CategoricalIndex,
1616
DataFrame,
1717
Index,
18+
Interval,
1819
IntervalIndex,
1920
MultiIndex,
2021
RangeIndex,
2122
Series,
2223
Timestamp,
24+
cut,
2325
date_range,
2426
)
2527
import pandas._testing as tm
@@ -682,3 +684,16 @@ def test_drop_pos_args_deprecation():
682684
result = df.reset_index("a", False)
683685
expected = DataFrame({"a": [1, 2, 3]})
684686
tm.assert_frame_equal(result, expected)
687+
688+
689+
def test_reset_index_interval_columns_object_cast():
690+
# GH 19136
691+
df = DataFrame(
692+
np.eye(2), index=Index([1, 2], name="Year"), columns=cut([1, 2], [0, 1, 2])
693+
)
694+
result = df.reset_index()
695+
expected = DataFrame(
696+
[[1, 1.0, 0.0], [2, 0.0, 1.0]],
697+
columns=Index(["Year", Interval(0, 1), Interval(1, 2)]),
698+
)
699+
tm.assert_frame_equal(result, expected)

pandas/tests/groupby/test_apply.py

+48
Original file line numberDiff line numberDiff line change
@@ -1199,3 +1199,51 @@ def test_apply_index_key_error_bug(index_values):
11991199
lambda df: Series([df["b"].mean()], index=["b_mean"])
12001200
)
12011201
tm.assert_frame_equal(result, expected)
1202+
1203+
1204+
@pytest.mark.parametrize(
1205+
"arg,idx",
1206+
[
1207+
[
1208+
[
1209+
1,
1210+
2,
1211+
3,
1212+
],
1213+
[
1214+
0.1,
1215+
0.3,
1216+
0.2,
1217+
],
1218+
],
1219+
[
1220+
[
1221+
1,
1222+
2,
1223+
3,
1224+
],
1225+
[
1226+
0.1,
1227+
0.2,
1228+
0.3,
1229+
],
1230+
],
1231+
[
1232+
[
1233+
1,
1234+
4,
1235+
3,
1236+
],
1237+
[
1238+
0.1,
1239+
0.4,
1240+
0.2,
1241+
],
1242+
],
1243+
],
1244+
)
1245+
def test_apply_nonmonotonic_float_index(arg, idx):
1246+
# GH 34455
1247+
expected = DataFrame({"col": arg}, index=idx)
1248+
result = expected.groupby("col").apply(lambda x: x)
1249+
tm.assert_frame_equal(result, expected)

pandas/tests/reshape/concat/test_categorical.py

+15
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,18 @@ def test_categorical_index_upcast(self):
223223
exp = Series([1, 2, 4, 3], index=["foo", "bar", "baz", "bar"])
224224

225225
tm.assert_equal(res, exp)
226+
227+
def test_categorical_missing_from_one_frame(self):
228+
# GH 25412
229+
df1 = DataFrame({"f1": [1, 2, 3]})
230+
df2 = DataFrame({"f1": [2, 3, 1], "f2": Series([4, 4, 4]).astype("category")})
231+
result = pd.concat([df1, df2], sort=True)
232+
dtype = CategoricalDtype([4])
233+
expected = DataFrame(
234+
{
235+
"f1": [1, 2, 3, 2, 3, 1],
236+
"f2": Categorical.from_codes([-1, -1, -1, 0, 0, 0], dtype=dtype),
237+
},
238+
index=[0, 1, 2, 0, 1, 2],
239+
)
240+
tm.assert_frame_equal(result, expected)

pandas/tests/scalar/timestamp/test_arithmetic.py

+9
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,12 @@ def test_addsub_m8ndarray_tzaware(self, shape):
310310
msg = r"unsupported operand type\(s\) for -: 'numpy.ndarray' and 'Timestamp'"
311311
with pytest.raises(TypeError, match=msg):
312312
other - ts
313+
314+
def test_subtract_different_utc_objects(self, utc_fixture, utc_fixture2):
315+
# GH 32619
316+
dt = datetime(2021, 1, 1)
317+
ts1 = Timestamp(dt, tz=utc_fixture)
318+
ts2 = Timestamp(dt, tz=utc_fixture2)
319+
result = ts1 - ts2
320+
expected = Timedelta(0)
321+
assert result == expected

0 commit comments

Comments
 (0)