Skip to content

RFC: refactor copy argument sanitizing into a unified compat function - #16170

Merged
mhvk merged 1 commit into
astropy:mainfrom
neutrinoceros:rfc/sanitize_copy_arg
Mar 10, 2024
Merged

mhvk merged 1 commit into
astropy:mainfrom
neutrinoceros:rfc/sanitize_copy_arg

Conversation

@neutrinoceros

Copy link
Copy Markdown
Contributor

Description

This is a follow up to #16142 so we have a single source of truth regarding how we treat user-provided copy=False arguments.

This is also a step forward followin my proposed long term plan (see #16167), but it's in itself not an API cchange and could be backported for convenience if desired.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions

github-actions Bot commented Mar 6, 2024

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@neutrinoceros
neutrinoceros force-pushed the rfc/sanitize_copy_arg branch from da04070 to bbb4391 Compare March 6, 2024 14:25
Comment thread astropy/utils/compat/numpycompat.py Outdated

def sanitize_copy_arg(copy, /):
if not NUMPY_LT_2_0 and copy is False:
# TODO: deprecate this path, and eventually remove this entire function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this TODO could be updated or removed. It isn't needed for this PR, and largely depends on future conversation in #16167

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(I removed it)

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought we agreed to just follow numpy 2.x convention if people have numpy 2.x, and if people want the old numpy 1.x behavior, they should just downgrade numpy back to 1.x. With that in mind, this PR is completely unnecessary?

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

This PR is actually older than the discussion, but I think it still has value in that it prevents that some paths are updated and not others. I could just remove or update the TODO comment to avoid making promises on the future.

@pllim
pllim requested a review from mhvk March 8, 2024 22:24
@mhvk

mhvk commented Mar 9, 2024

Copy link
Copy Markdown
Contributor

Is this still needed? The conclusion to just live with whatever numpy does suggests that all we need to do is update any copy=False defaults to copy=COPY_IF_NEEDED (with the old COPY_IF_NEEDED = False if NUMPY_LT_2_0 else None) and that otherwise code can remain untouched. Or am I missing something?

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

That was indeed a clear consensus amongst participants in the last dev telecon, however we also agreed that we should ultimately involve downstream stake holders and give them a chance to test different approaches so we can settle for the most aggressive one that doesn't cause too much immediate pain. With this in mind, there are two alternative continuations to this PR:

the second one just removes the function I'm introducing here, but the first one creates a deprecation path instead. So, if it turns out downstream players are not affected by the API change, we'll indeed just end up removing this function. However, given the uncertainty, I believe there is still value in having one source of truth instead of multiple instances of this code bits.
I would also argue that it could actually be more work to not merge this one since I'd need to slightly refactor #16174 and #16181 . Nothing too bad, but from where I stand this one is just a button push away from done.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I see, I missed that c a deprecation warning would indeed much more easily raised inside a function. Since you're all set up to do this, and we will either end up removing this or adding a deprecation warning, I think this is good to go. Thanks, @neutrinoceros!

@mhvk

mhvk commented Mar 9, 2024

Copy link
Copy Markdown
Contributor

p.s. Not sure what's up with the tests that just seem to be waiting to be run.

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

I think that's a side effect of merging #15603. If it's blocking I can rebase this one.

@mhvk

mhvk commented Mar 9, 2024

Copy link
Copy Markdown
Contributor

I cannot override the statuses, so, yes, maybe best to rebase so we can actually merge...

@neutrinoceros
neutrinoceros force-pushed the rfc/sanitize_copy_arg branch from 428d39c to 519536e Compare March 9, 2024 15:44
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

done

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

Oh, actually blocked by scientific-python/pytest-doctestplus#242

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

closing/reopening to retrigger CI now that pytest-doctestplus was updated

@neutrinoceros neutrinoceros reopened this Mar 10, 2024
@neutrinoceros
neutrinoceros force-pushed the rfc/sanitize_copy_arg branch from 519536e to f5071ab Compare March 10, 2024 07:29
@neutrinoceros
neutrinoceros force-pushed the rfc/sanitize_copy_arg branch from f5071ab to 805b16b Compare March 10, 2024 07:31
@mhvk

mhvk commented Mar 10, 2024

Copy link
Copy Markdown
Contributor

OK, thanks, let's get this in so the other two can be rebased...

@mhvk
mhvk merged commit cad8a70 into astropy:main Mar 10, 2024
@neutrinoceros
neutrinoceros deleted the rfc/sanitize_copy_arg branch March 10, 2024 12:43
@neutrinoceros

neutrinoceros commented Mar 10, 2024 •

Copy link
Copy Markdown
Contributor Author

Thanks Marten ! every child branches is now rebased and conflict-free

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.

3 participants