Skip to content

TST: Add regression tests for old issues #45095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pandas/tests/frame/methods/test_combine_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,12 @@ def test_combine_first_duplicates_rows_for_nan_index_values():
)
combined = df1.combine_first(df2)
tm.assert_frame_equal(combined, expected)


def test_combine_first_int64_not_cast_to_float64():
# GH 28613
df_1 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
df_2 = DataFrame({"A": [1, 20, 30], "B": [40, 50, 60], "C": [12, 34, 65]})
result = df_1.combine_first(df_2)
expected = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [12, 34, 65]})
tm.assert_frame_equal(result, expected)
15 changes: 15 additions & 0 deletions pandas/tests/frame/methods/test_reset_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
CategoricalIndex,
DataFrame,
Index,
Interval,
IntervalIndex,
MultiIndex,
RangeIndex,
Series,
Timestamp,
cut,
date_range,
)
import pandas._testing as tm
Expand Down Expand Up @@ -682,3 +684,16 @@ def test_drop_pos_args_deprecation():
result = df.reset_index("a", False)
expected = DataFrame({"a": [1, 2, 3]})
tm.assert_frame_equal(result, expected)


def test_reset_index_interval_columns_object_cast():
# GH 19136
df = DataFrame(
np.eye(2), index=Index([1, 2], name="Year"), columns=cut([1, 2], [0, 1, 2])
)
result = df.reset_index()
expected = DataFrame(
[[1, 1.0, 0.0], [2, 0.0, 1.0]],
columns=Index(["Year", Interval(0, 1), Interval(1, 2)]),
)
tm.assert_frame_equal(result, expected)
48 changes: 48 additions & 0 deletions pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,3 +1199,51 @@ def test_apply_index_key_error_bug(index_values):
lambda df: Series([df["b"].mean()], index=["b_mean"])
)
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"arg,idx",
[
[
[
1,
2,
3,
],
[
0.1,
0.3,
0.2,
],
],
[
[
1,
2,
3,
],
[
0.1,
0.2,
0.3,
],
],
[
[
1,
4,
3,
],
[
0.1,
0.4,
0.2,
],
],
],
)
def test_apply_nonmonotonic_float_index(arg, idx):
# GH 34455
expected = DataFrame({"col": arg}, index=idx)
result = expected.groupby("col").apply(lambda x: x)
tm.assert_frame_equal(result, expected)
15 changes: 15 additions & 0 deletions pandas/tests/reshape/concat/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,18 @@ def test_categorical_index_upcast(self):
exp = Series([1, 2, 4, 3], index=["foo", "bar", "baz", "bar"])

tm.assert_equal(res, exp)

def test_categorical_missing_from_one_frame(self):
# GH 25412
df1 = DataFrame({"f1": [1, 2, 3]})
df2 = DataFrame({"f1": [2, 3, 1], "f2": Series([4, 4, 4]).astype("category")})
result = pd.concat([df1, df2], sort=True)
dtype = CategoricalDtype([4])
expected = DataFrame(
{
"f1": [1, 2, 3, 2, 3, 1],
"f2": Categorical.from_codes([-1, -1, -1, 0, 0, 0], dtype=dtype),
},
index=[0, 1, 2, 0, 1, 2],
)
tm.assert_frame_equal(result, expected)
9 changes: 9 additions & 0 deletions pandas/tests/scalar/timestamp/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,12 @@ def test_addsub_m8ndarray_tzaware(self, shape):
msg = r"unsupported operand type\(s\) for -: 'numpy.ndarray' and 'Timestamp'"
with pytest.raises(TypeError, match=msg):
other - ts

def test_subtract_different_utc_objects(self, utc_fixture, utc_fixture2):
# GH 32619
dt = datetime(2021, 1, 1)
ts1 = Timestamp(dt, tz=utc_fixture)
ts2 = Timestamp(dt, tz=utc_fixture2)
result = ts1 - ts2
expected = Timedelta(0)
assert result == expected