Skip to content

Commit 17e0584

Browse files
mroeschkeJulianWgs
authored andcommitted
TST: Add tests for old issues (pandas-dev#41482)
1 parent 180ab1c commit 17e0584

File tree

8 files changed

+81
-0
lines changed

8 files changed

+81
-0
lines changed

pandas/tests/apply/test_frame_apply.py

+8
Original file line numberDiff line numberDiff line change
@@ -1519,3 +1519,11 @@ def test_apply_np_reducer(float_frame, op, how):
15191519
getattr(np, op)(float_frame, axis=0, **kwargs), index=float_frame.columns
15201520
)
15211521
tm.assert_series_equal(result, expected)
1522+
1523+
1524+
def test_apply_getitem_axis_1():
1525+
# GH 13427
1526+
df = DataFrame({"a": [0, 1, 2], "b": [1, 2, 3]})
1527+
result = df[["a", "a"]].apply(lambda x: x[0] + x[1], axis=1)
1528+
expected = Series([0, 2, 4])
1529+
tm.assert_series_equal(result, expected)

pandas/tests/frame/methods/test_drop.py

+9
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,12 @@ def test_drop_with_duplicate_columns2(self):
481481
df2 = df.take([2, 0, 1, 2, 1], axis=1)
482482
result = df2.drop("C", axis=1)
483483
tm.assert_frame_equal(result, expected)
484+
485+
def test_drop_inplace_no_leftover_column_reference(self):
486+
# GH 13934
487+
df = DataFrame({"a": [1, 2, 3]})
488+
a = df.a
489+
df.drop(["a"], axis=1, inplace=True)
490+
tm.assert_index_equal(df.columns, Index([], dtype="object"))
491+
a -= a.mean()
492+
tm.assert_index_equal(df.columns, Index([], dtype="object"))

pandas/tests/frame/test_reductions.py

+9
Original file line numberDiff line numberDiff line change
@@ -1638,3 +1638,12 @@ def test_groupy_regular_arithmetic_equivalent(meth):
16381638

16391639
result = getattr(df.groupby(level=0), meth)(numeric_only=False)
16401640
tm.assert_frame_equal(result, expected)
1641+
1642+
1643+
@pytest.mark.parametrize("ts_value", [Timestamp("2000-01-01"), pd.NaT])
1644+
def test_frame_mixed_numeric_object_with_timestamp(ts_value):
1645+
# GH 13912
1646+
df = DataFrame({"a": [1], "b": [1.1], "c": ["foo"], "d": [ts_value]})
1647+
result = df.sum()
1648+
expected = Series([1, 1.1, "foo"], index=list("abc"))
1649+
tm.assert_series_equal(result, expected)

pandas/tests/frame/test_stack_unstack.py

+15
Original file line numberDiff line numberDiff line change
@@ -2018,3 +2018,18 @@ def test_stack_nan_level(self):
20182018
),
20192019
)
20202020
tm.assert_frame_equal(result, expected)
2021+
2022+
def test_unstack_categorical_columns(self):
2023+
# GH 14018
2024+
idx = MultiIndex.from_product([["A"], [0, 1]])
2025+
df = DataFrame({"cat": pd.Categorical(["a", "b"])}, index=idx)
2026+
result = df.unstack()
2027+
expected = DataFrame(
2028+
{
2029+
0: pd.Categorical(["a"], categories=["a", "b"]),
2030+
1: pd.Categorical(["b"], categories=["a", "b"]),
2031+
},
2032+
index=["A"],
2033+
)
2034+
expected.columns = MultiIndex.from_tuples([("cat", 0), ("cat", 1)])
2035+
tm.assert_frame_equal(result, expected)

pandas/tests/indexes/base_class/test_setops.py

+12
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,15 @@ def test_union_name_preservation(
247247
else:
248248
expected = Index(vals, name=expected_name)
249249
tm.equalContents(union, expected)
250+
251+
@pytest.mark.parametrize(
252+
"diff_type, expected",
253+
[["difference", [1, "B"]], ["symmetric_difference", [1, 2, "B", "C"]]],
254+
)
255+
def test_difference_object_type(self, diff_type, expected):
256+
# GH 13432
257+
idx1 = Index([0, 1, "A", "B"])
258+
idx2 = Index([0, 2, "A", "C"])
259+
result = getattr(idx1, diff_type)(idx2)
260+
expected = Index(expected)
261+
tm.assert_index_equal(result, expected)

pandas/tests/indexing/multiindex/test_loc.py

+13
Original file line numberDiff line numberDiff line change
@@ -788,3 +788,16 @@ def test_mi_columns_loc_list_label_order():
788788
columns=MultiIndex.from_tuples([("B", 1), ("B", 2), ("A", 1), ("A", 2)]),
789789
)
790790
tm.assert_frame_equal(result, expected)
791+
792+
793+
def test_mi_partial_indexing_list_raises():
794+
# GH 13501
795+
frame = DataFrame(
796+
np.arange(12).reshape((4, 3)),
797+
index=[["a", "a", "b", "b"], [1, 2, 1, 2]],
798+
columns=[["Ohio", "Ohio", "Colorado"], ["Green", "Red", "Green"]],
799+
)
800+
frame.index.names = ["key1", "key2"]
801+
frame.columns.names = ["state", "color"]
802+
with pytest.raises(KeyError, match="\\[2\\] not in index"):
803+
frame.loc[["b", 2], "Colorado"]

pandas/tests/indexing/test_chaining_and_caching.py

+7
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,10 @@ def test_iloc_setitem_chained_assignment(self):
499499

500500
df["bb"].iloc[0] = 0.15
501501
assert df["bb"].iloc[0] == 0.15
502+
503+
def test_getitem_loc_assignment_slice_state(self):
504+
# GH 13569
505+
df = DataFrame({"a": [10, 20, 30]})
506+
df["a"].loc[4] = 40
507+
tm.assert_frame_equal(df, DataFrame({"a": [10, 20, 30]}))
508+
tm.assert_series_equal(df["a"], Series([10, 20, 30], name="a"))

pandas/tests/io/test_common.py

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Tests for the pandas.io.common functionalities
33
"""
44
import codecs
5+
import errno
56
from functools import partial
67
from io import (
78
BytesIO,
@@ -519,3 +520,10 @@ def test_bad_encdoing_errors():
519520
with tm.ensure_clean() as path:
520521
with pytest.raises(ValueError, match="Invalid value for `encoding_errors`"):
521522
icom.get_handle(path, "w", errors="bad")
523+
524+
525+
def test_errno_attribute():
526+
# GH 13872
527+
with pytest.raises(FileNotFoundError, match="\\[Errno 2\\]") as err:
528+
pd.read_csv("doesnt_exist")
529+
assert err.errno == errno.ENOENT

0 commit comments

Comments
 (0)