Skip to content

Commit cd764ec

Browse files
committed
refine Exceptions
1 parent 646b3f8 commit cd764ec

27 files changed

+325
-327
lines changed

build/lib/data_algebra/PostgreSQL.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def __init__(self):
1919

2020
def quote_identifier(self, identifier):
2121
if not isinstance(identifier, str):
22-
raise Exception("expected identifier to be a str")
22+
raise TypeError("expected identifier to be a str")
2323
if self.identifier_quote in identifier:
24-
raise Exception('did not expect " in identifier')
24+
raise ValueError('did not expect " in identifier')
2525
return self.identifier_quote + identifier.lower() + self.identifier_quote
2626

2727
def build_qualified_table_name(self, table_name, *, qualifiers=None):

build/lib/data_algebra/SQLite.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ def prepare_connection(self, conn):
4747

4848
def quote_identifier(self, identifier):
4949
if not isinstance(identifier, str):
50-
raise Exception("expected identifier to be a str")
50+
raise TypeError("expected identifier to be a str")
5151
if self.identifier_quote in identifier:
52-
raise Exception('did not expect " in identifier')
52+
raise ValueError('did not expect " in identifier')
5353
return self.identifier_quote + identifier + self.identifier_quote
5454

5555
def quote_table_name(self, table_description):
5656
if not isinstance(table_description, data_algebra.data_ops.TableDescription):
57-
raise Exception(
57+
raise TypeError(
5858
"Expected table_description to be a data_algebra.data_ops.TableDescription)"
5959
)
6060
if len(table_description.qualifiers) > 0:
61-
raise Exception("SQLite adapter does not currently support qualifiers")
61+
raise RuntimeError("SQLite adapter does not currently support qualifiers")
6262
qt = self.quote_identifier(table_description.table_name)
6363
return qt
6464

@@ -73,7 +73,7 @@ def insert_table(self, conn, d, table_name):
7373
"""
7474

7575
if not isinstance(d, pandas.DataFrame):
76-
raise Exception("d is supposed to be a pandas.DataFrame")
76+
raise TypeError("d is supposed to be a pandas.DataFrame")
7777
cur = conn.cursor()
7878
cur.execute("DROP TABLE IF EXISTS " + table_name)
7979
d.to_sql(name=table_name, con=conn)

build/lib/data_algebra/cdata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class RecordSpecification:
88
def __init__(self, control_table, *, record_keys=None, control_table_keys=None):
99
if not isinstance(control_table, pandas.DataFrame):
10-
raise Exception("control_table should be a pandas.DataFrame")
10+
raise TypeError("control_table should be a pandas.DataFrame")
1111
self.control_table = control_table.copy()
1212
self.control_table.reset_index(inplace=True, drop=True)
1313
if record_keys is None:
@@ -18,7 +18,7 @@ def __init__(self, control_table, *, record_keys=None, control_table_keys=None):
1818
self.control_table_keys = [k for k in control_table_keys]
1919
confused = set(record_keys).intersection(control_table_keys)
2020
if len(confused) > 0:
21-
raise Exception(
21+
raise ValueError(
2222
"columns common to record_keys and control_table_keys: " + str(confused)
2323
)
2424

build/lib/data_algebra/cdata_impl.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def table_is_keyed_by_columns(table, column_names):
1212
# check for ill-condition
1313
missing_columns = set(column_names) - set([c for c in table.columns])
1414
if len(missing_columns) > 0:
15-
raise Exception("missing columns: " + str(missing_columns))
15+
raise KeyError("missing columns: " + str(missing_columns))
1616
# get rid of some corner cases
1717
if table.shape[0] < 2:
1818
return True
@@ -33,16 +33,16 @@ class RecordMap:
3333
def __init__(self, *, blocks_in=None, blocks_out=None):
3434
if blocks_in is not None:
3535
if not isinstance(blocks_in, data_algebra.cdata.RecordSpecification):
36-
raise Exception(
36+
raise TypeError(
3737
"blocks_in should be a data_algebra.cdata.RecordSpecification"
3838
)
3939
if blocks_out is not None:
4040
if not isinstance(blocks_out, data_algebra.cdata.RecordSpecification):
41-
raise Exception(
41+
raise TypeError(
4242
"blocks_out should be a data_algebra.cdata.RecordSpecification"
4343
)
4444
if (blocks_in is None) and (blocks_out is None):
45-
raise Exception(
45+
raise ValueError(
4646
"At least one of blocks_in or blocks_out should not be None"
4747
)
4848
self.blocks_in = blocks_in
@@ -54,7 +54,7 @@ def transform(
5454
self, X, *, check_blocks_in_keying=True, check_blocks_out_keying=False
5555
):
5656
if not isinstance(X, pandas.DataFrame):
57-
raise Exception("X should be a pandas.DataFrame")
57+
raise TypeError("X should be a pandas.DataFrame")
5858
X = X.copy()
5959
X.reset_index(inplace=True, drop=True)
6060
db_model = data_algebra.SQLite.SQLiteModel()
@@ -66,14 +66,14 @@ def transform(
6666
self.blocks_in.record_keys
6767
) - set(x1_descr.column_names)
6868
if len(missing_cols) > 0:
69-
raise Exception("missing required columns: " + str(missing_cols))
69+
raise KeyError("missing required columns: " + str(missing_cols))
7070
# convert to row-records
7171
if check_blocks_in_keying:
7272
# table should be keyed by record_keys + control_table_keys
7373
if not table_is_keyed_by_columns(
7474
X, self.blocks_in.record_keys + self.blocks_in.control_table_keys
7575
):
76-
raise Exception(
76+
raise ValueError(
7777
"table is not keyed by blocks_in.record_keys + blocks_in.control_table_keys"
7878
)
7979
with sqlite3.connect(":memory:") as conn:
@@ -88,11 +88,11 @@ def transform(
8888
)
8989
missing_cols = set(self.blocks_out.record_keys) - set(x2_descr.column_names)
9090
if len(missing_cols) > 0:
91-
raise Exception("missing required columns: " + str(missing_cols))
91+
raise KeyError("missing required columns: " + str(missing_cols))
9292
if check_blocks_out_keying:
9393
# table should be keyed by record_keys
9494
if not table_is_keyed_by_columns(X, self.blocks_out.record_keys):
95-
raise Exception("table is not keyed by blocks_out.record_keys")
95+
raise ValueError("table is not keyed by blocks_out.record_keys")
9696
# convert to block records
9797
with sqlite3.connect(":memory:") as conn:
9898
temp_table = data_algebra.data_ops.TableDescription(

0 commit comments

Comments
 (0)