Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
Don't sort table headers alphabetically if we don't have an `OrderedD…
Browse files Browse the repository at this point in the history
…ict`

Rregular dicts are sorted in Python 3, we dropped Python 2 a while ago so no need now.
Should resolve loss of header order in custom content.
Fixes MultiQC#1866
  • Loading branch information
ewels committed May 4, 2023
1 parent 623e0a1 commit c68ad81
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Table code now tolerates lambda function calls with bad data ([#1739](https://github.com/ewels/MultiQC/issues/1739))
- Beeswarm plot now saves data to `multiqc_data`, same as tables ([#1861](https://github.com/ewels/MultiQC/issues/1861))
- Don't print DOI in module if it's set to an empty string.
- Don't sort table headers alphabetically if we don't have an `OrderedDict` - regular dicts are fine in Py3 ([#1866](https://github.com/ewels/MultiQC/issues/1866))

### New Modules

Expand Down
12 changes: 3 additions & 9 deletions multiqc/plots/table_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,12 @@ def __init__(self, data, headers=None, pconfig=None):
)

# Overwrite shared key settings and at the same time assign to buckets for sorting
# Within each section of headers, sort explicitly by 'title' if the dict
# is not already ordered, so the final ordering is by:
# placement > section > explicit_ordering > title
# So the final ordering is:
# placement > section > explicit_ordering
# Of course, the user can shuffle these manually.
self.headers_in_order = defaultdict(list)

for idx, hs in enumerate(headers):
keys_in_section = hs.keys()
if type(hs) is not OrderedDict:
keys_in_section = sorted(keys_in_section, key=lambda k: headers[idx][k]["title"])

for k in keys_in_section:
for k in hs.keys():
sk = headers[idx][k]["shared_key"]
if sk is not None:
headers[idx][k]["dmax"] = shared_keys[sk]["dmax"]
Expand Down

0 comments on commit c68ad81

Please sign in to comment.