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

Update shift() for issue #1145 #1194

Merged
merged 4 commits into from
Oct 19, 2024
Merged

Conversation

psyuktha
Copy link
Contributor

@psyuktha psyuktha commented Oct 17, 2024

Pull Request Checklist

Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:

  • 🧪 Added tests for changed code.
  • 🛠️ All tests pass when run locally (run tox or make test to find out!).
  • 🧹 All linting checks pass when run locally (run tox -e lint or make lint to find out!).
  • 📚 Updated documentation for changed code.
  • ⏩ Code is up-to-date with the master branch.

If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!

Description of Changes

Added check_imaginary parameter to the function referring to the issue #1145

  • New Parameter: Added a check_imaginary parameter (defaulting to True), which allows the user to decide whether or not to perform DST/imaginary time checks.
  • Skip DST Check: The DST check logic:
    block is only executed if check_imaginary is True. If set to False, this check is skipped for improved performance when DST changes are not a concern.

Benefits:

  • Backward Compatibility: By default, the method still performs the DST/imaginary time checks, so existing code won't break.
  • Performance Boost: Users who know that their datetime range does not involve DST transitions can set check_imaginary=False to skip the checks and improve performance.

@@ -492,7 +492,7 @@ def range(

values = [getattr(current, f) for f in cls._ATTRS]
current = cls(*values, tzinfo=tzinfo).shift( # type: ignore[misc]
**{frame_relative: relative_steps}
check_imaginary=True, **{frame_relative: relative_steps}
Copy link
Member

Choose a reason for hiding this comment

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

Mind explaining why we want to force usage of check imaginary here rather than making it an argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To bypass unnecessary checks when performance matters and they know they won't encounter DST transitions.

The default behavior of check_imaginary=True ensures that users get correct and valid results by default. If a user deliberately wants to skip the check for performance reasons or because they're confident it isn't needed, they can do so by setting the parameter to False.

Copy link
Member

Choose a reason for hiding this comment

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

Ah my bad, I now see that this was added as true in range and dehumanize shift usages to maintain backwards compatibility right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes exactly

@psyuktha
Copy link
Contributor Author

@jadchaar If all the requirements are met, can you please approve it?

Copy link
Member

@jadchaar jadchaar left a comment

Choose a reason for hiding this comment

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

LGTM

@jadchaar jadchaar merged commit 403c29f into arrow-py:master Oct 19, 2024
18 checks passed
@psyuktha
Copy link
Contributor Author

psyuktha commented Oct 19, 2024

Could you please add a Hacktoberfest accepted label to this, will be helpful

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.

2 participants