Skip to content

Commit

Permalink
Merge pull request #56 from dr-rodriguez/master
Browse files Browse the repository at this point in the history
Fix for issue #53 and some error handling
  • Loading branch information
hover2pi committed Jun 16, 2016
2 parents 43ff40a + 39d72c2 commit 27d50fd
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions astrodbkit/astrodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ def add_data(self, data, table, delimiter='|', bands=''):
columns, types, required = [np.array(metadata[n]) for n in ['name', 'type', 'notnull']]
new_records = at.Table(names=columns, dtype=[type_dict[t] for t in types])

# Convert data dtypes to those of the existing table
for col in data.colnames:
try:
temp = data[col].astype(new_records[col].dtype)
data.replace_column(col, temp)
except KeyError:
continue

# If a row contains photometry for multiple bands, use the *multiband argument and execute this
if bands and table.lower() == 'photometry':

Expand Down Expand Up @@ -552,8 +560,13 @@ def _lowest_rowids(self, table, limit):
An array of all available row ids
"""
ids = self.query("SELECT id FROM {}".format(table), unpack=True)[0]
all_ids = np.array(range(1, max(ids)))
try:
ids = self.query("SELECT id FROM {}".format(table), unpack=True)[0]
all_ids = np.array(range(1, max(ids)))
except TypeError:
ids = None
all_ids = np.array(range(1, limit+1))

available = all_ids[np.in1d(all_ids, ids, assume_unique=True, invert=True)][:limit]

# If there aren't enough empty row ids, start using the new ones
Expand Down Expand Up @@ -969,7 +982,10 @@ def schema(self, table):
The table name
"""
pprint(self.query("PRAGMA table_info({})".format(table), fmt='table'))
try:
pprint(self.query("PRAGMA table_info({})".format(table), fmt='table'))
except ValueError:
print('Table {} not found'.format(table))

def search(self, criterion, table, columns='', fetch=False):
"""
Expand Down

0 comments on commit 27d50fd

Please sign in to comment.