Skip to content

TST: Add tests for fixed issues #30769

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 3 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions pandas/tests/frame/methods/test_sort_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,22 @@ def test_sort_values_ignore_index(

tm.assert_frame_equal(result_df, expected)
tm.assert_frame_equal(df, DataFrame(original_dict))

def test_sort_values_nat_na_position_default(self):
# GH 13230
expected = pd.DataFrame(
{
"A": [1, 2, 3, 4, 4],
"date": pd.DatetimeIndex(
[
"2010-01-01 09:00:00",
"2010-01-01 09:00:01",
"2010-01-01 09:00:02",
"2010-01-01 09:00:03",
"NaT",
]
),
}
)
result = expected.sort_values(["A", "date"])
tm.assert_frame_equal(result, expected)
12 changes: 12 additions & 0 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,18 @@ def test_apply_dup_names_multi_agg(self):

tm.assert_frame_equal(result, expected)

def test_apply_nested_result_axis_1(self):
# GH 13820
def apply_list(row):
return [2 * row["A"], 2 * row["C"], 2 * row["B"]]

df = pd.DataFrame(np.zeros((4, 4)), columns=list("ABCD"))
result = df.apply(apply_list, axis=1)
expected = Series(
[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
)
tm.assert_series_equal(result, expected)


class TestInferOutputShape:
# the user has supplied an opaque UDF where
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,14 @@ def test_zero_len_frame_with_series_corner_cases():
result = df + ser
expected = df
tm.assert_frame_equal(result, expected)


def test_frame_single_columns_object_sum_axis_1():
# GH 13758
data = {
"One": pd.Series(["A", 1.2, np.nan]),
}
df = pd.DataFrame(data)
result = df.sum(axis=1)
expected = pd.Series(["A", 1.2, 0])
tm.assert_series_equal(result, expected)
7 changes: 7 additions & 0 deletions pandas/tests/series/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,3 +780,10 @@ def test_apply_scaler_on_date_time_index_aware_series(self):
series = tm.makeTimeSeries(nper=30).tz_localize("UTC")
result = pd.Series(series.index).apply(lambda x: 1)
tm.assert_series_equal(result, pd.Series(np.ones(30), dtype="int64"))

def test_map_float_to_string_precision(self):
# GH 13228
x = pd.Series(1 / 3)
Copy link
Member

Choose a reason for hiding this comment

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

minor nit, s or ser.

result = x.map(lambda val: str(val)).to_dict()
expected = {0: "0.3333333333333333"}
assert result == expected
18 changes: 18 additions & 0 deletions pandas/tests/series/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ def test_flex_method_equivalence(self, opname, ts):
expected = alt(other, series)
tm.assert_almost_equal(result, expected)

@pytest.mark.parametrize(
"opname", ["add", "sub", "mul", "floordiv", "truediv", "pow"]
Copy link
Member

Choose a reason for hiding this comment

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

is it possible to use all_arithmetic_operators fixture here

)
def test_flex_method_subclass_metadata_preservation(self, opname):
# GH 13208
class MySeries(Series):
_metadata = ["x"]

@property
def _constructor(self):
return MySeries

op = getattr(Series, opname)
m = MySeries([1, 2, 3], name="test")
m.x = 42
result = op(m, 1)
assert result.x == 42


class TestSeriesArithmetic:
# Some of these may end up in tests/arithmetic, but are not yet sorted
Expand Down