Skip to content
Open
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
41 changes: 33 additions & 8 deletions pandasmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def readLevel(self, y=0, xs=0, xe=None, orient=None):
section_start = i
v=label
if y+1<len(c.levels):
children = self.readLevel(y+1, section_start, orient=orient)
children = self.readLevel(y+1, section_start, xe, orient=orient)
sibl[-1].appendRow(children)
return sibl

Expand Down Expand Up @@ -475,13 +475,38 @@ def sort(self, column, order):
QtGui.QVBoxLayout(form).addWidget(view)
form.show()

#Prepare data
tuples=[('bar', 'one', 'q'), ('bar', 'two', 'q'), ('baz', 'one', 'q'), ('baz', 'two', 'q'),
('foo', 'one', 'q'), ('foo', 'two', 'q'), ('qux', 'one', 'q'), ('qux', 'two', 'q')]
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second', 'third'])
df=pd.DataFrame(pd.np.random.randn(6, 6), index=index[:6], columns=index[:6])
print("DataFrame:\n%s"%df)

test_case = 2

if test_case == 1:
# Prepare sample data with 3 index levels
tuples = [('A', 'one', 'X'), ('A', 'one', 'Y'), ('A', 'two', 'X'), ('A', 'two', 'Y'),
('B', 'one', 'X'), ('B', 'one', 'Y'), ('B', 'two', 'X'), ('B', 'two', 'Y')]
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second', 'third'])
df = pd.DataFrame(pd.np.random.randint(0, 10, (8, 8)), index=index[:8], columns=index[:8])

if test_case == 2:
# Prepare sample data with 3 index levels all unique
tuples = [('A', 'one', 'a'), ('B', 'two', 'b'), ('C', 'three', 'c'), ('D', 'four', 'd'),
('E', 'five', 'e'), ('F', 'six', 'f'), ('G', 'seven', 'g'), ('H', 'eight', 'h')]
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second', 'third'])
df = pd.DataFrame(pd.np.random.randint(0, 10, (8, 8)), index=index[:8], columns=index[:8])

if test_case == 3:
# Prepare sample data with 2 index levels
tuples = [('A', 'one'), ('A', 'two'),
('B', 'one'), ('B', 'two')]
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
df = pd.DataFrame(pd.np.random.randint(0, 10, (4, 4)), index=index[:8], columns=index[:8])

if test_case == 4:
# Prepare sample data basic
data = pd.np.random.randint(0, 10, (10, 3)).astype(float)
data[0][0] = pd.np.nan
print(data)
df = pd.DataFrame(data, columns=['col1', 'col2', 'col3'])

print("DataFrame:\n%s" % df)

#Prepare view
# oldh, oldv = view.horizontalHeader(), view.verticalHeader()
# oldh.setParent(form), oldv.setParent(form) #Save old headers for some reason
Expand Down