Pandas version checks
- [X] I have checked that the issue still exists on the latest versions of the docs on
mainhere
Location of the documentation
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html
Documentation problem
The navigation bar in the API reference documentation is not sorted in alphabetical order!
current navigation example order copied directly from the page.
Dataframe pandas.DataFrame pandas.DataFrame.index pandas.DataFrame.columns pandas.DataFrame.dtypes pandas.DataFrame.info pandas.DataFrame.select_dtypes pandas.DataFrame.values pandas.DataFrame.axes pandas.DataFrame.ndim pandas.DataFrame.size pandas.DataFrame.shape pandas.DataFrame.memory_usage pandas.DataFrame.empty
Why is this a problem?
As a developer starting to work with Python and Pandas When reviewing the Pandas API reference docs Then it is really easy to miss behaviour that I would want to use, because of how it is sorted
Suggested fix for documentation
Sort the documentation alphabetically.
Comment From: SiddheshBangar
@jeropaul Thanks for sharing this issue, I had a look into this, and it is actually a long list to be fixed. If it is required to be fixed let me know, I will open a PR
Comment From: rhshadrach
The order is in the sections that appear on this page - https://pandas.pydata.org/docs/reference/frame.html. Are we able to order that page independently of the sidebar? If not, I'd be -1 on having a lexicographical ordering across all DataFrame methods.
Comment From: jeropaul
I also note that pandas.DataFrame.tail is listed in the navigation bar twice for the DataFrame... I suspect that this happens because it appears in both 'Reindexing / selection / label manipulation' and 'Indexing, iteration'. Not a significant issue but it is kinda weird.
Being honest I did not even notice the right hand side menu bar until @rhshadrach pointed it out...
Comment From: sooooooing
take
Comment From: DoNguyenHung
take
Comment From: DoNguyenHung
Hi @rhshadrach, I was wondering if you could take off the "Needs Discussion" tag for this issue? I submitted a pull request that was able to sort the sidebar independently of the page. Unfortunately, it was closed because of the tag, even though the tag's been up for over a year. Thanks in advance!
Comment From: rhshadrach
From the linked PR:
I do believe this will make navigation easier. You good with this @mroeschke?
Comment From: mroeschke
It looks good, as long as there's ideally a way to do this with Sphinx directly instead of Javascript
Comment From: DoNguyenHung
Hi @mroeschke, I've already tried multiple approaches to address this but I ran into 2 main issues: 1. generate_toctree_html() returns unpredictable output (sometimes None). So I couldn't use 'split()' to split the items and sort them. This is an example of what I tried:
{% set toc = generate_toctree_html(
"sidebar",
maxdepth=4,
collapse=True,
includehidden=True,
titles_only=True
) %}
{% set toc_items = toc.split('<li>') %}
{% set sorted_items = toc_items[1:]|sort(case_sensitive=False) %}
- The template system doesn't reliably expose the node structure needed for sorting. I tried adding a sorting method to conf.py, but the items end up not changing in their positioning because most nodes are raw HTML fragments.
for node in doctree.traverse(bullet_list):
# Sort both top-level and nested items
node.children = sorted(
node.children,
key=lambda x: x.astext().lower().strip()
)
I hope that makes sense.