Skip to content

TST/REF: parametrize set_axis tests #37619

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
Nov 4, 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
16 changes: 0 additions & 16 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime

import numpy as np
import pytest

from pandas.core.dtypes.common import (
is_categorical_dtype,
Expand All @@ -24,15 +23,6 @@


class TestDataFrameAlterAxes:
def test_set_index_directly(self, float_string_frame):
df = float_string_frame
idx = Index(np.arange(len(df))[::-1])

df.index = idx
tm.assert_index_equal(df.index, idx)
with pytest.raises(ValueError, match="Length mismatch"):
df.index = idx[::2]

def test_convert_dti_to_series(self):
# don't cast a DatetimeIndex WITH a tz, leave as object
# GH 6032
Expand Down Expand Up @@ -101,12 +91,6 @@ def test_convert_dti_to_series(self):
df.pop("ts")
tm.assert_frame_equal(df, expected)

def test_set_columns(self, float_string_frame):
cols = Index(np.arange(len(float_string_frame.columns)))
float_string_frame.columns = cols
with pytest.raises(ValueError, match="Length mismatch"):
float_string_frame.columns = cols[::2]

def test_dti_set_index_reindex(self):
# GH 6631
df = DataFrame(np.random.random(6))
Expand Down
22 changes: 22 additions & 0 deletions pandas/tests/generic/methods/test_set_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ def test_set_axis_invalid_axis_name(self, axis, obj):
with pytest.raises(ValueError, match="No axis named"):
obj.set_axis(list("abc"), axis=axis)

def test_set_axis_setattr_index_not_collection(self, obj):
# wrong type
msg = (
r"Index\(\.\.\.\) must be called with a collection of some "
r"kind, None was passed"
)
with pytest.raises(TypeError, match=msg):
obj.index = None

def test_set_axis_setattr_index_wrong_length(self, obj):
# wrong length
msg = (
f"Length mismatch: Expected axis has {len(obj)} elements, "
f"new values have {len(obj)-1} elements"
)
with pytest.raises(ValueError, match=msg):
obj.index = np.arange(len(obj) - 1)

if obj.ndim == 2:
with pytest.raises(ValueError, match="Length mismatch"):
obj.columns = obj.columns[::2]


class TestDataFrameSetAxis(SharedSetAxisTests):
@pytest.fixture
Expand Down
21 changes: 21 additions & 0 deletions pandas/tests/series/methods/test_set_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from datetime import datetime

from pandas import Series


class TestSetName:
def test_set_name(self):
ser = Series([1, 2, 3])
ser2 = ser._set_name("foo")
assert ser2.name == "foo"
assert ser.name is None
assert ser is not ser2

def test_set_name_attribute(self):
ser = Series([1, 2, 3])
ser2 = Series([1, 2, 3], name="bar")
for name in [7, 7.0, "name", datetime(2001, 1, 1), (1,), "\u05D0"]:
ser.name = name
assert ser.name == name
ser2.name = name
assert ser2.name == name
55 changes: 0 additions & 55 deletions pandas/tests/series/test_alter_axes.py

This file was deleted.