Patching Dec 9, 2021 6-7a CST- All GitLab services may be unavailable for 5-10 minutes

Commit acee2ca5 authored by Matthew Krafczyk's avatar Matthew Krafczyk
Browse files

Add two new tests to check functionality with multiindex columns.

parent fe5110f7
import pandas as pd
import pandas_sequence as pds
import numpy as np
import pytest
def test_basic_group_col_1_1():
# Build test DataFrame
......@@ -745,3 +746,72 @@ def test_nogrouping_3():
target_df.columns = pd.MultiIndex.from_tuples(list(target_df.columns))
pd.testing.assert_frame_equal(sequenced_df, target_df)
def test_multiindex_col_1():
# Build test DataFrame
df = pd.DataFrame(
[[1,1],
[1,2],
[1,3],
[1,4],
[2,1],
[2,2],
[2,3],
[3,1]],
columns=pd.MultiIndex.from_tuples([('Category', 'Group'), ('Category', 'Value')]),
index=[0,1,2,3,4,5,6,7]
)
sequenced_df = pds.sequence_df(df, [-1,0], group_specs=[('group', 'column', ('Category', 'Group'))])
target_df = pd.DataFrame(
[[1,2],
[2,3],
[3,4],
[1,2],
[2,3]],
columns=pd.MultiIndex.from_product([[('Category', 'Value')],[-1,0]]),
index=[1,2,3,5,6])
pd.testing.assert_frame_equal(sequenced_df, target_df)
@pytest.mark.xfail
def test_tuples_col_1():
# This test currently fails because pandas expects column index to be a multiindex if all elements are tuples.
# The failure I ran into was this:
# pandas_sequence/sequence.py:289: in sequence_df
# slice_df = temp_gbydf.shift(-lag)
#/usr/lib/python3.9/site-packages/pandas/core/groupby/groupby.py:2980: in shift
# return self._get_cythonized_result(
#/usr/lib/python3.9/site-packages/pandas/core/groupby/groupby.py:2945: in _get_cythonized_result
# return self._wrap_transformed_output(output)
#/usr/lib/python3.9/site-packages/pandas/core/groupby/generic.py:1670: in _wrap_transformed_output
# columns._set_names(self.obj._get_axis(1 - self.axis).names)
# ValueError: Length of names must match number of levels in MultiIndex.
# Build test DataFrame
df = pd.DataFrame(
[[1,1],
[1,2],
[1,3],
[1,4],
[2,1],
[2,2],
[2,3],
[3,1]],
columns=[('Category', 'Group'), ('Category', 'Value')],
index=[0,1,2,3,4,5,6,7]
)
sequenced_df = pds.sequence_df(df, [-1,0], group_specs=[('group', 'column', ('Category', 'Group'))])
target_df = pd.DataFrame(
[[1,2],
[2,3],
[3,4],
[1,2],
[2,3]],
columns=pd.MultiIndex.from_product([[('Category', 'Value')],[-1,0]]),
index=[1,2,3,5,6])
pd.testing.assert_frame_equal(sequenced_df, target_df)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment