Skip to content
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

handel indexes with more than one column #13

Merged
merged 1 commit into from
Dec 12, 2016
Merged
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
15 changes: 9 additions & 6 deletions orca_test/orca_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def assert_column_is_registered(table_name, column_name):
assert_table_can_be_generated(table_name)
t = orca.get_table(table_name)

if (column_name not in t.columns) and (column_name != t.index.name):
if (column_name not in t.columns) and (column_name not in t.index.names):
msg = "Column '%s' is not registered in table '%s'" % (column_name, table_name)
raise OrcaAssertionError(msg)
return
Expand All @@ -311,7 +311,7 @@ def assert_column_not_registered(table_name, column_name):
assert_table_can_be_generated(table_name)
t = orca.get_table(table_name)

if (column_name in t.columns) or (column_name == t.index.name):
if (column_name in t.columns) or (column_name in t.index.names):
msg = "Column '%s' is already registered in table '%s'" % (column_name, table_name)
raise OrcaAssertionError(msg)
return
Expand Down Expand Up @@ -340,7 +340,7 @@ def assert_column_can_be_generated(table_name, column_name):
t = orca.get_table(table_name)

# t.column_type() fails for index columns, so we have to check for them separately
if column_name == t.index.name:
if column_name in t.index.names:
return

elif t.column_type(column_name) == 'function':
Expand Down Expand Up @@ -372,6 +372,10 @@ def assert_column_is_primary_key(table_name, column_name):
assert_column_can_be_generated(table_name, column_name)

idx = orca.get_table(table_name).index
if len(idx.names) > 1:
msg = "The table '%s' has a multi-index, and primary key checks are not yet supported." \
% table_name
raise OrcaAssertionError(msg)
if idx.name != column_name:
msg = "Column '%s' is not set as the index of table '%s'" \
% (column_name, table_name)
Expand Down Expand Up @@ -448,9 +452,8 @@ def get_column_or_index(table_name, column_name):
assert_column_can_be_generated(table_name, column_name)
t = orca.get_table(table_name)

if column_name == t.index.name:
return pd.Series(t.index)

if column_name in t.index.names:
return t.to_frame([]).reset_index()[column_name]
else:
return t.get_column(column_name)

Expand Down