Skip to content

TST/REF: collect tests by method #37434

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 1 commit into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 29 additions & 0 deletions pandas/tests/frame/methods/test_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@


class TestDataFrameValues:
def test_values(self, float_frame):
float_frame.values[:, 0] = 5.0
assert (float_frame.values[:, 0] == 5).all()

def test_more_values(self, float_string_frame):
values = float_string_frame.values
assert values.shape[1] == len(float_string_frame.columns)

def test_values_mixed_dtypes(self, float_frame, float_string_frame):
frame = float_frame
arr = frame.values

frame_cols = frame.columns
for i, row in enumerate(arr):
for j, value in enumerate(row):
col = frame_cols[j]
if np.isnan(value):
assert np.isnan(frame[col][i])
else:
assert value == frame[col][i]

# mixed type
arr = float_string_frame[["foo", "A"]].values
assert arr[0, 0] == "bar"

df = DataFrame({"complex": [1j, 2j, 3j], "real": [1, 2, 3]})
arr = df.values
assert arr[0, 0] == 1j

def test_values_duplicates(self):
df = DataFrame(
[[1, 2, "a", "b"], [1, 2, "a", "b"]], columns=["one", "one", "two", "two"]
Expand Down
44 changes: 0 additions & 44 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ def test_getitem_pop_assign_name(self, float_frame):
s2 = s.loc[:]
assert s2.name == "B"

def test_get_value(self, float_frame):
for idx in float_frame.index:
for col in float_frame.columns:
result = float_frame._get_value(idx, col)
expected = float_frame[col][idx]
tm.assert_almost_equal(result, expected)

def test_add_prefix_suffix(self, float_frame):
with_prefix = float_frame.add_prefix("foo#")
expected = pd.Index([f"foo#{c}" for c in float_frame.columns])
Expand Down Expand Up @@ -315,27 +308,6 @@ def test_sequence_like_with_categorical(self):
def test_len(self, float_frame):
assert len(float_frame) == len(float_frame.index)

def test_values_mixed_dtypes(self, float_frame, float_string_frame):
frame = float_frame
arr = frame.values

frame_cols = frame.columns
for i, row in enumerate(arr):
for j, value in enumerate(row):
col = frame_cols[j]
if np.isnan(value):
assert np.isnan(frame[col][i])
else:
assert value == frame[col][i]

# mixed type
arr = float_string_frame[["foo", "A"]].values
assert arr[0, 0] == "bar"

df = DataFrame({"complex": [1j, 2j, 3j], "real": [1, 2, 3]})
arr = df.values
assert arr[0, 0] == 1j

# single block corner case
arr = float_frame[["A", "B"]].values
expected = float_frame.reindex(columns=["A", "B"]).values
Expand Down Expand Up @@ -394,18 +366,6 @@ def test_class_axis(self):
assert pydoc.getdoc(DataFrame.index)
assert pydoc.getdoc(DataFrame.columns)

def test_more_values(self, float_string_frame):
values = float_string_frame.values
assert values.shape[1] == len(float_string_frame.columns)

def test_repr_with_mi_nat(self, float_string_frame):
df = DataFrame(
{"X": [1, 2]}, index=[[pd.NaT, pd.Timestamp("20130101")], ["a", "b"]]
)
result = repr(df)
expected = " X\nNaT a 1\n2013-01-01 b 2"
assert result == expected

def test_items_names(self, float_string_frame):
for k, v in float_string_frame.items():
assert v.name == k
Expand Down Expand Up @@ -447,10 +407,6 @@ def test_with_datetimelikes(self):
expected = Series({np.dtype("object"): 10})
tm.assert_series_equal(result, expected)

def test_values(self, float_frame):
float_frame.values[:, 0] = 5.0
assert (float_frame.values[:, 0] == 5).all()

def test_deepcopy(self, float_frame):
cp = deepcopy(float_frame)
series = cp["A"]
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/frame/test_repr_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
Categorical,
DataFrame,
MultiIndex,
NaT,
PeriodIndex,
Series,
Timestamp,
date_range,
option_context,
period_range,
Expand All @@ -36,6 +38,12 @@ def test_assign_index_sequences(self):
df.index = index
repr(df)

def test_repr_with_mi_nat(self, float_string_frame):
df = DataFrame({"X": [1, 2]}, index=[[NaT, Timestamp("20130101")], ["a", "b"]])
result = repr(df)
expected = " X\nNaT a 1\n2013-01-01 b 2"
assert result == expected

def test_multiindex_na_repr(self):
# only an issue with long columns
df3 = DataFrame(
Expand Down