-
Notifications
You must be signed in to change notification settings - Fork 35
Description
Description
When using hapi.fetch(...), hapi.select(...), and hapi.getColumns(...) there are inconsistencies with case sensitivity of the parameter names. Parameter names passed to hapi.fetch(...) are case sensitive, those passed to hapi.getColumns(...) are not case sensitive, but only if the table is created from a hapi.fetch(...) call, otherwise they are case sensitive. Parameter names passed to `hapi.select(...)' are case sensitive.
Also parameter names are inconsistent in case style. e.g. 'gamma_air' vs 'gamma_CO2'. The first is all lower case, the second is mixed case. Choosing a single convention (e.g. parameters are lower case but gas names are always uppercase) and documenting it would help the user.
The problem is likely due to using CaseInsensitveDict (or CaselessDict as it renamed on line 446) inconsistently. Either all dictionaries should be created without case sensitivity or all dictionaries should be case sensitive.
Recreation of error
The following code snippet recreates the error:
# HITRAN API testing
import os, os.path
import hapi
# Make folder for database
db_dir = 'local_test_database'
table_name = 'H2O_TEST'
os.makedirs(db_dir, exist_ok=True)
# Remove previously downloaded files to make this test re-runnable
for x in os.listdir(db_dir):
os.remove(os.path.join(db_dir, x))
# Initialise database and download problematic data
hapi.db_begin(db_dir)
hapi.fetch(table_name, 1, 1, 2999, 3000, Parameters=('nu','gamma_air')) # works
#hapi.fetch(table_name, 1, 1, 2999, 3000, Parameters=('nu','GAMMA_AIR')) # fails
#hapi.fetch(table_name, 1, 1, 2999, 3000, Parameters=('nu','gamma_co2')) # fails
#hapi.fetch(table_name, 1, 1, 2999, 3000, Parameters=('nu','GAMMA_CO2')) # fails
hapi.fetch(table_name, 1, 1, 2999, 3000, Parameters=('nu','gamma_CO2')) # works
hapi.describeTable(table_name)
cols = hapi.getColumns(
table_name,
[
'nu',
'gamma_air', # works
'GAMMA_AIR', # works
'gamma_co2', # works
'GAMMA_CO2', # works
'gamma_CO2', # works
]
)
print(f'cols.shape = {tuple(len(x) for x in cols)}')
print(f'{cols[0]=}')
print(f'{cols[1]=}')
print(f'{cols[2]=}')
print(f'{cols[3]=}')
print(f'{cols[4]=}')
print(f'{cols[5]=}')
#hapi.select(table_name, DestinationTableName='temp', ParameterNames=('nu', 'gamma_air')) # works
hapi.select(table_name, DestinationTableName='temp', ParameterNames=('nu', 'GAMMA_AIR')) # fails
hapi.describeTable('temp')
cols_2 = hapi.getColumns(
'temp',
[
'nu',
#'gamma_air', # works
'GAMMA_AIR', # fails
]
)
print(f'cols_2.shape = {tuple(len(x) for x in cols_2)}')
print(f'{cols_2[0]=}')
print(f'{cols_2[1]=}')
# Commit database transaction to save to disk
hapi.db_commit()