Skip to content

Commit 5d407cf

Browse files
authored
TST: Add tests for fixed issues (#30769)
* TST: Add tests for fixed issues * Address review
1 parent 3f57ae7 commit 5d407cf

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

pandas/tests/frame/methods/test_sort_values.py

+19
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,22 @@ def test_sort_values_ignore_index(
497497

498498
tm.assert_frame_equal(result_df, expected)
499499
tm.assert_frame_equal(df, DataFrame(original_dict))
500+
501+
def test_sort_values_nat_na_position_default(self):
502+
# GH 13230
503+
expected = pd.DataFrame(
504+
{
505+
"A": [1, 2, 3, 4, 4],
506+
"date": pd.DatetimeIndex(
507+
[
508+
"2010-01-01 09:00:00",
509+
"2010-01-01 09:00:01",
510+
"2010-01-01 09:00:02",
511+
"2010-01-01 09:00:03",
512+
"NaT",
513+
]
514+
),
515+
}
516+
)
517+
result = expected.sort_values(["A", "date"])
518+
tm.assert_frame_equal(result, expected)

pandas/tests/frame/test_apply.py

+12
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,18 @@ def test_apply_dup_names_multi_agg(self):
691691

692692
tm.assert_frame_equal(result, expected)
693693

694+
def test_apply_nested_result_axis_1(self):
695+
# GH 13820
696+
def apply_list(row):
697+
return [2 * row["A"], 2 * row["C"], 2 * row["B"]]
698+
699+
df = pd.DataFrame(np.zeros((4, 4)), columns=list("ABCD"))
700+
result = df.apply(apply_list, axis=1)
701+
expected = Series(
702+
[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
703+
)
704+
tm.assert_series_equal(result, expected)
705+
694706

695707
class TestInferOutputShape:
696708
# the user has supplied an opaque UDF where

pandas/tests/frame/test_arithmetic.py

+11
Original file line numberDiff line numberDiff line change
@@ -726,3 +726,14 @@ def test_zero_len_frame_with_series_corner_cases():
726726
result = df + ser
727727
expected = df
728728
tm.assert_frame_equal(result, expected)
729+
730+
731+
def test_frame_single_columns_object_sum_axis_1():
732+
# GH 13758
733+
data = {
734+
"One": pd.Series(["A", 1.2, np.nan]),
735+
}
736+
df = pd.DataFrame(data)
737+
result = df.sum(axis=1)
738+
expected = pd.Series(["A", 1.2, 0])
739+
tm.assert_series_equal(result, expected)

pandas/tests/series/test_apply.py

+7
Original file line numberDiff line numberDiff line change
@@ -780,3 +780,10 @@ def test_apply_scaler_on_date_time_index_aware_series(self):
780780
series = tm.makeTimeSeries(nper=30).tz_localize("UTC")
781781
result = pd.Series(series.index).apply(lambda x: 1)
782782
tm.assert_series_equal(result, pd.Series(np.ones(30), dtype="int64"))
783+
784+
def test_map_float_to_string_precision(self):
785+
# GH 13228
786+
ser = pd.Series(1 / 3)
787+
result = ser.map(lambda val: str(val)).to_dict()
788+
expected = {0: "0.3333333333333333"}
789+
assert result == expected

pandas/tests/series/test_arithmetic.py

+16
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ def test_flex_method_equivalence(self, opname, ts):
4747
expected = alt(other, series)
4848
tm.assert_almost_equal(result, expected)
4949

50+
def test_flex_method_subclass_metadata_preservation(self, all_arithmetic_operators):
51+
# GH 13208
52+
class MySeries(Series):
53+
_metadata = ["x"]
54+
55+
@property
56+
def _constructor(self):
57+
return MySeries
58+
59+
opname = all_arithmetic_operators
60+
op = getattr(Series, opname)
61+
m = MySeries([1, 2, 3], name="test")
62+
m.x = 42
63+
result = op(m, 1)
64+
assert result.x == 42
65+
5066

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

0 commit comments

Comments
 (0)