WRI-Cities / static-GTFS-manager

GUI interface for creating, editing, exporting of static GTFS data for a public transit authority
GNU General Public License v3.0
147 stars 46 forks source link

Ordering of columns changing in table after editing #151

Closed answerquest closed 4 years ago

answerquest commented 5 years ago

Operating system

Ubuntu / Linux

Python version

Python 3.6.5, Virtual environment.

Problem description

Ordering of columns in tables changes after we add a new item (in this case, see in trips) Console output:

GTFSManager.py:535: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default.
To accept the future behavior, pass 'sort=False'.
To retain the current behavior and silence the warning, pass 'sort=True'.

In Delete ID page, we get a raw data preview and there we can see the trips table's columns ordering has now been sorted alphabetically:

bikes_allowed   block_id    direction_id    route_id    service_id  shape_id    trip_headsign   trip_id trip_short_name wheelchair_accessible

This doesn't have an executive impact on our data; but it's annoying to have loaded in a GTFS with things sorted the way we wanted them; and then on exporting all the columns have been tosssed up.

Expected Action

Preserve the original columns order in the table when someone adds a new trip, route etc or edits one.

answerquest commented 5 years ago

Traced to the root of the problem: under function replaceTableDB, there's a pandas .concat() statement without a sort parameter:

df3 = pd.concat([df,xdf], ignore_index=True)

And that makes pandas automatically sort all columns alphabetically. Documentation.
Need to set sort=False

So, changed the line to:

df3 = pd.concat([df,xdf], ignore_index=True, sort=False)

Changed .concat() statements at 3 other places as well.

Hope that fixes it.

answerquest commented 5 years ago

Fixed in latest commit. Will close this when a proper release is done.