Skip to content

Commit

Permalink
TST: tests for needs-test issues pandas-dev#12857 pandas-dev#12689 (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and AlexKirko committed Dec 29, 2019
1 parent 34e3ab6 commit 7872f78
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
class TestFrameComparisons:
# Specifically _not_ flex-comparisons

def test_frame_in_list(self):
# GH#12689 this should raise at the DataFrame level, not blocks
df = pd.DataFrame(np.random.randn(6, 4), columns=list("ABCD"))
msg = "The truth value of a DataFrame is ambiguous"
with pytest.raises(ValueError, match=msg):
df in [None]

def test_comparison_invalid(self):
def check(df, df2):

Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@


class TestDataFrameConstructors:
def test_series_with_name_not_matching_column(self):
# GH#9232
x = pd.Series(range(5), name=1)
y = pd.Series(range(5), name=0)

result = pd.DataFrame(x, columns=[0])
expected = pd.DataFrame([], columns=[0])
tm.assert_frame_equal(result, expected)

result = pd.DataFrame(y, columns=[1])
expected = pd.DataFrame([], columns=[1])
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize(
"constructor",
[
Expand Down
31 changes: 31 additions & 0 deletions pandas/tests/io/parser/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,34 @@ def test_multi_index_unnamed(all_parsers, index_col, columns):
columns = MultiIndex.from_tuples(zip(exp_columns, ["0", "1"]))
expected = DataFrame([[2, 3], [4, 5]], columns=columns)
tm.assert_frame_equal(result, expected)


def test_read_csv_multiindex_columns(all_parsers):
# GH#6051
parser = all_parsers

s1 = "Male, Male, Male, Female, Female\nR, R, L, R, R\n.86, .67, .88, .78, .81"
s2 = (
"Male, Male, Male, Female, Female\n"
"R, R, L, R, R\n"
".86, .67, .88, .78, .81\n"
".86, .67, .88, .78, .82"
)

mi = MultiIndex.from_tuples(
[
("Male", "R"),
(" Male", " R"),
(" Male", " L"),
(" Female", " R"),
(" Female", " R.1"),
]
)
expected = DataFrame(
[[0.86, 0.67, 0.88, 0.78, 0.81], [0.86, 0.67, 0.88, 0.78, 0.82]], columns=mi
)

df1 = parser.read_csv(StringIO(s1), header=[0, 1])
tm.assert_frame_equal(df1, expected.iloc[:1])
df2 = parser.read_csv(StringIO(s2), header=[0, 1])
tm.assert_frame_equal(df2, expected)

0 comments on commit 7872f78

Please sign in to comment.