Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
xfailing for now, needs axis reconstruction to succeed
  • Loading branch information
jreback committed Mar 15, 2017
1 parent 8054e6c commit 61301b4
Showing 1 changed file with 45 additions and 32 deletions.
77 changes: 45 additions & 32 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def setUp(self):
self.ymd.index.set_names(['year', 'month', 'day'], inplace=True)



class TestMultiLevel(Base, tm.TestCase):

def test_append(self):
Expand Down Expand Up @@ -215,7 +214,6 @@ def test_reindex_preserve_levels(self):
chunk = ymdT.loc[:, new_index]
self.assertIs(chunk.columns, new_index)


def test_repr_to_string(self):
repr(self.frame)
repr(self.ymd)
Expand Down Expand Up @@ -713,7 +711,6 @@ def test_getitem_partial_column_select(self):
self.assertRaises(KeyError, df.loc.__getitem__,
(('a', 'foo'), slice(None, None)))


def test_delevel_infer_dtype(self):
tuples = [tuple
for tuple in cart_product(
Expand All @@ -737,7 +734,6 @@ def test_reset_index_with_drop(self):
deleveled = self.series.reset_index(drop=True)
tm.assertIsInstance(deleveled, Series)


def test_count_level(self):
def _check_counts(frame, axis=0):
index = frame._get_axis(axis)
Expand Down Expand Up @@ -2358,26 +2354,6 @@ def test_sorting_repr_8017(self):
result = result.sort_index(axis=1)
tm.assert_frame_equal(result, expected)

def test_getitem_multilevel_index_tuple_unsorted(self):
index_columns = list("abc")
df = DataFrame([[0, 1, 0, "x"], [0, 0, 1, "y"]],
columns=index_columns + ["data"])
df = df.set_index(index_columns)
query_index = df.index[:1]
rs = df.loc[query_index, "data"]

xp_idx = MultiIndex.from_tuples([(0, 1, 0)], names=['a', 'b', 'c'])
xp = Series(['x'], index=xp_idx, name='data')
tm.assert_series_equal(rs, xp)

def test_getitem_slice_not_sorted(self):
df = self.frame.sort_index(level=1).T

# buglet with int typechecking
result = df.iloc[:, :np.int32(3)]
expected = df.reindex(columns=df.columns[:3])
tm.assert_frame_equal(result, expected)

def test_sort_index_level(self):
df = self.frame.copy()
df.index = np.arange(len(df))
Expand Down Expand Up @@ -2497,14 +2473,6 @@ def test_sort_index_and_reconstruction(self):
assert result.columns.is_lexsorted()
assert result.columns.is_monotonic

# def test_
#df = pd.DataFrame({'col1': ['b','d','b','a'], 'col2': [3,1,1,2], 'data':['one','two','three','four']})

#In [121]: df2 = df.set_index(['col1','col2'])

#In [122]: df2.index.set_levels(['b','d','a'], level='col1', inplace=True)

#In [123]: df2.index.set_labels([0,1,0,2], level='col1', inplace=True)
def test_is_lexsorted(self):
levels = [[0, 1], [0, 1, 2]]

Expand All @@ -2521,6 +2489,26 @@ def test_is_lexsorted(self):
self.assertFalse(index.is_lexsorted())
self.assertEqual(index.lexsort_depth, 0)

def test_getitem_multilevel_index_tuple_not_sorted(self):
index_columns = list("abc")
df = DataFrame([[0, 1, 0, "x"], [0, 0, 1, "y"]],
columns=index_columns + ["data"])
df = df.set_index(index_columns)
query_index = df.index[:1]
rs = df.loc[query_index, "data"]

xp_idx = MultiIndex.from_tuples([(0, 1, 0)], names=['a', 'b', 'c'])
xp = Series(['x'], index=xp_idx, name='data')
tm.assert_series_equal(rs, xp)

def test_getitem_slice_not_sorted(self):
df = self.frame.sort_index(level=1).T

# buglet with int typechecking
result = df.iloc[:, :np.int32(3)]
expected = df.reindex(columns=df.columns[:3])
tm.assert_frame_equal(result, expected)

def test_frame_getitem_not_sorted(self):
df = self.frame.T
df['foo', 'four'] = 'foo'
Expand All @@ -2542,6 +2530,31 @@ def test_frame_getitem_not_sorted(self):
tm.assert_frame_equal(result, expected)
tm.assert_frame_equal(result2, expected)

@pytest.mark.xfail(reason="need axis reconstruction")
def test_frame_getitem_not_sorted2(self):
# 13431
df = DataFrame({'col1': ['b', 'd', 'b', 'a'],
'col2': [3, 1, 1, 2],
'data': ['one', 'two', 'three', 'four']})

df2 = df.set_index(['col1', 'col2'])
df2_original = df2.copy()

df2.index.set_levels(['b', 'd', 'a'], level='col1', inplace=True)
df2.index.set_labels([0, 1, 0, 2], level='col1', inplace=True)
assert not df2.index.is_lexsorted()
assert not df2.index.is_monotonic

assert df2_original.index.equals(df2.index)

result = df2.sort_index()
assert result.index.is_lexsorted()
assert result.index.is_monotonic

result = df2.sort_index(level=0)
assert result.index.is_lexsorted()
assert result.index.is_monotonic

def test_series_getitem_not_sorted(self):
arrays = [['bar', 'bar', 'baz', 'baz', 'qux', 'qux', 'foo', 'foo'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
Expand Down

0 comments on commit 61301b4

Please sign in to comment.