Skip to content

TST: tests for needs-test issues #12857 #12689 #30327

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 12 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from 8 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
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 @@ -42,6 +42,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
11 changes: 11 additions & 0 deletions pandas/tests/frame/test_repr_info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta
from io import StringIO
import random
import re
import sys
import textwrap
Expand Down Expand Up @@ -27,6 +28,16 @@


class TestDataFrameReprInfoEtc:
def test_repr_bytes_61_lines(self):
# GH#12857
lets = "ACDEFGHIJKLMNOP"
slen = 50
nseqs = 1000
words = [[random.choice(lets) for x in range(slen)] for _ in range(nseqs)]
df = pd.DataFrame(words).astype("S1")
assert (df.dtypes == "S1").all()
repr(df) # smoke test

def test_repr_empty(self):
# empty
foo = repr(DataFrame()) # noqa
Expand Down
31 changes: 30 additions & 1 deletion pandas/tests/io/parser/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from pandas.errors import ParserError

from pandas import DataFrame, Index, MultiIndex
from pandas import DataFrame, Index, MultiIndex, read_csv
import pandas.util.testing as tm


Expand Down Expand Up @@ -540,3 +540,32 @@ 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():
# GH#6051
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 = read_csv(StringIO(s1), header=[0, 1])
tm.assert_frame_equal(df1, expected.iloc[:1])
df2 = read_csv(StringIO(s2), header=[0, 1])
tm.assert_frame_equal(df2, expected)