LANL-Seismoacoustics / pisces

Pisces: A practical seismological database library in Python.
http://lanl-seismoacoustics.github.io/pisces/
Other
17 stars 10 forks source link

why are wfdisc rows being sorted in alphabetic order? #73

Open jwebster-LANL opened 1 year ago

jwebster-LANL commented 1 year ago

A (new) error popped up in infraview that is related (i think) to pisces. I had programmed infraview's database waveform acquisition assuming the wfdisc rows had a field order as given in https://nappe.wustl.edu/antelope/css-formats/wfdisc.htm This has worked up until recently when it seems the wfdisc rows I've been getting back from pisces have the fields sorted in alphabetic order. The code snippit I've been using is:

my_query =  ps.request.get_wfdisc_rows(session, db_tables['wfdisc'], chan=cha, t1=start_time, t2=end_time, asquery=True)
my_query = my_query.filter(db_tables['wfdisc'].sta.like(sta))
if asquery:
    return my_query
else:
    return my_query.all()

I checked and the result of the query is sorted with columns in alphabetical order.

I don't see anything in pisces that would cause this...does anyone have an idea about changed?

jkmacc-LANL commented 1 year ago

@jwebster-LANL, hmmm. I think you were the last person to modify get_wfdisc_rows, so I haven't made any changes there. Can you share what you mean by "sorted with columns in alphabetical order"? It looks like your query would return a list row instances with column attributes like wf.sta and wf.dfile, which aren't ordered. Are you saying that when you do something like print(*wf), the correct order isn't preserved?

jwebster-LANL commented 1 year ago

If you do a query like..

wfs = database.query_db(session, tables, start_time=start_time, end_time=end_time, sta=sta, cha=cha, return_type='wfdisc_rows')
        print(wfs[0])

The wfdisc row lists come out ordered such that the attributes are in alphabetic order, as opposed to the field order as described in the link above

python 3.9.16 sqlalchemy 1.4.39 pisces 0.4.2 (from github) pyqt 5.15.7

let me know what else you might need

jkmacc-LANL commented 1 year ago

When I upgrade to sqlalchemy 2.*, this problem goes away. I'm currently trying to find the SQLAlchemy version at which this behavior changed...

...crud, it appears to be a problem with all of SQLAlchemy 1.4! Would that be disruptive to you if we were sqla>1.4?