Skip to content

Commit

Permalink
adjust for comments II
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 committed Jul 7, 2019
1 parent 3a19d89 commit 5bcf204
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
3 changes: 1 addition & 2 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,7 @@ def test_reset_index(self, float_frame):
):
values = lev.take(level_codes)
name = names[i]
tm.assert_index_equal(values, Index(deleveled[name]), check_names=False)
assert values.name is None
tm.assert_index_equal(values, Index(deleveled[name].rename(name=None)))

stacked.index.names = [None, None]
deleveled2 = stacked.reset_index()
Expand Down
10 changes: 4 additions & 6 deletions pandas/tests/indexes/multi/test_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
import pandas.util.testing as tm


def check_level_names(index, names):
assert [level.name for level in index.levels] == list(names)


def test_reindex(idx):
result, indexer = idx.reindex(list(idx[:4]))
assert isinstance(result, MultiIndex)
check_level_names(result, [None, None])
assert result.names == ["first", "second"]
assert [level.name for level in result.levels] == [None, None]

result, indexer = idx.reindex(list(idx))
assert isinstance(result, MultiIndex)
assert indexer is None
check_level_names(result, [None, None])
assert result.names == ["first", "second"]
assert [level.name for level in result.levels] == [None, None]


def test_reindex_level(idx):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/reshape/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def test_reshaping_multi_index_categorical(self):
df.index.names = ["major", "minor"]
df["str"] = "foo"

dti = df.index.levels[0].set_names(["major"])
dti = df.index.levels[0].rename("major")

df["category"] = df["str"].astype("category")
result = df["category"].unstack()
Expand Down
28 changes: 16 additions & 12 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,8 @@ def test_frame_group_ops(self, op, level, axis, skipna, sort):
self.frame.iloc[1, [1, 2]] = np.nan
self.frame.iloc[7, [0, 1]] = np.nan

level_name = self.frame.index.names[level]

if axis == 0:
frame = self.frame
else:
Expand All @@ -1016,12 +1018,12 @@ def aggf(x):
frame = frame.sort_index(level=level, axis=axis)

# for good measure, groupby detail
level_index = frame._get_axis(axis).levels[level]
level_index = frame._get_axis(axis).levels[level].rename(level_name)

tm.assert_index_equal(leftside._get_axis(axis), level_index, check_names=False)
tm.assert_index_equal(rightside._get_axis(axis), level_index, check_names=False)
tm.assert_index_equal(leftside._get_axis(axis), level_index)
tm.assert_index_equal(rightside._get_axis(axis), level_index)

tm.assert_frame_equal(leftside, rightside, check_names=False)
tm.assert_frame_equal(leftside, rightside)

def test_stat_op_corner(self):
obj = Series([10.0], index=MultiIndex.from_tuples([(2, 3)]))
Expand Down Expand Up @@ -1607,12 +1609,15 @@ def test_constructor_with_tz(self):
)

result = MultiIndex.from_arrays([index, columns])
tm.assert_index_equal(result.levels[0], index, check_names=False)
tm.assert_index_equal(result.levels[1], columns, check_names=False)
assert result.names == ["dt1", "dt2"]
# levels don't have names set, so set name of index/columns to None in checks
tm.assert_index_equal(result.levels[0], index.rename(None))
tm.assert_index_equal(result.levels[1], columns.rename(None))

result = MultiIndex.from_arrays([Series(index), Series(columns)])
tm.assert_index_equal(result.levels[0], index, check_names=False)
tm.assert_index_equal(result.levels[1], columns, check_names=False)
assert result.names == ["dt1", "dt2"]
tm.assert_index_equal(result.levels[0], index.rename(None))
tm.assert_index_equal(result.levels[1], columns.rename(None))

def test_set_index_datetime(self):
# GH 3950
Expand All @@ -1634,19 +1639,18 @@ def test_set_index_datetime(self):
df.index = df.index.tz_convert("US/Pacific")

expected = pd.DatetimeIndex(
["2011-07-19 07:00:00", "2011-07-19 08:00:00", "2011-07-19 09:00:00"],
name="datetime",
["2011-07-19 07:00:00", "2011-07-19 08:00:00", "2011-07-19 09:00:00"]
)
expected = expected.tz_localize("UTC").tz_convert("US/Pacific")

df = df.set_index("label", append=True)
tm.assert_index_equal(df.index.levels[0], expected, check_names=False)
tm.assert_index_equal(df.index.levels[0], expected)
tm.assert_index_equal(df.index.levels[1], Index(["a", "b"]))
assert df.index.names == ["datetime", "label"]

df = df.swaplevel(0, 1)
tm.assert_index_equal(df.index.levels[0], Index(["a", "b"]))
tm.assert_index_equal(df.index.levels[1], expected, check_names=False)
tm.assert_index_equal(df.index.levels[1], expected)
assert df.index.names == ["label", "datetime"]

df = DataFrame(np.random.random(6))
Expand Down

0 comments on commit 5bcf204

Please sign in to comment.