Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-110067: Make max heap methods public and add missing ones #130725

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

StanFromIreland
Copy link
Contributor

@StanFromIreland StanFromIreland commented Mar 1, 2025

Made public, added test (same as normal heap) and added docs.

@rhettinger has not opened the planned PR in ~2 years


📚 Documentation preview 📚: https://cpython-previews--130725.org.readthedocs.build/

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are various things to change. I don't know why we should expose the Python implementation and not the C implementation which is faster.

@bedevere-app
Copy link

bedevere-app bot commented Mar 1, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@StanFromIreland
Copy link
Contributor Author

I was working on the C implementation, my bad!

@StanFromIreland
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Mar 1, 2025

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz March 1, 2025 15:40
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would group _max with their non-max variants and update their descriptions since they are effictively different.

@bedevere-app
Copy link

bedevere-app bot commented Mar 1, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz picnixz marked this pull request as draft March 1, 2025 15:48
@picnixz
Copy link
Member

picnixz commented Mar 1, 2025

I'm converting into a draft until the comments are addressed. In addition, since we are now having code duplication for heappushpop_max and heappushpop, we could perhaps refactor the common logic (but maybe not in this PR yet)

StanFromIreland and others added 3 commits March 1, 2025 16:03
@StanFromIreland
Copy link
Contributor Author

StanFromIreland commented Mar 1, 2025

I have made the requested changes; please review again

We can leave de-duplication for later.

@bedevere-app
Copy link

bedevere-app bot commented Mar 1, 2025

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz March 1, 2025 16:11
@bedevere-app
Copy link

bedevere-app bot commented Mar 1, 2025

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz March 1, 2025 18:25
@StanFromIreland
Copy link
Contributor Author

Also most of the requested changes can also be done for the existing code (I tried to stay consistent) should I open a second PR updating them to todays standards?

@picnixz
Copy link
Member

picnixz commented Mar 1, 2025

Also most of the requested changes can also be done for the existing code (I tried to stay consistent) should I open a second PR updating them to todays standards?

I wouldn't for now. We should however wonder we can reduce the code duplication if possible. But this would need Raymond's approval.

@StanFromIreland StanFromIreland requested a review from picnixz March 2, 2025 11:30
Comment on lines 570 to 578
* Make :mod:`heapq` max-heap functions

* :func:`heapq.heapify_max`,
* :func:`heapq.heappush_max`,
* :func:`heapq.heappop_max`,
* :func:`heapq.heapreplace_max`

public. And add the missing :func:`heapq.heappushpop_max` to
both the C and Python implementation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph needs some rewriting but I don't have time for now. But the idea is here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote it a bit nicer (at least in my opinion), is it better?

@@ -0,0 +1,11 @@
Make :mod:`heapq` max-heap functions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blurb entries cannot have new lines. I'll suggest something else later the day.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed new lines

@StanFromIreland
Copy link
Contributor Author

StanFromIreland commented Mar 2, 2025

@rhettinger, I would greatly appreciate your review :-)

Currently this has been done:

  • Addition of heappushpop_max in both the py and C implementation.
  • Existing *_max functions have been made public in both the py and C implementation however the old private names are still kept for backwards compatibility.
  • All *_max functions are tested just like their min-heap equivalents. (Some tests have been modernized) See coverage below
  • All of the *_max functions have been documented (some minor things left to clean up) (with the help of @picnixz :-)

Is there anything else left to do?

coverage report

image

@rhettinger rhettinger self-assigned this Mar 2, 2025
@StanFromIreland
Copy link
Contributor Author

@rhettinger friendly ping so this doesn't get lost in your todo list :-)

@picnixz
Copy link
Member

picnixz commented Mar 7, 2025

(Usually we wait 1 or 2 weeks for a friendly ping)

@rhettinger
Copy link
Contributor

I do want to review this but won't have time for a while. If there is a strong need to press forward (I'm not sure why), then another core-dev can take-over. Otherwise, it may have to sit for a little while.

@StanFromIreland
Copy link
Contributor Author

It seems to be quite a desired feature looking at the discuss and stack overflow. By while do you mean a week or two or a few months?

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relevant deadline is 3.14 beta, in early May.
I can take-over if the little while is measured in months.

@StanFromIreland StanFromIreland requested a review from encukou March 10, 2025 17:21
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants