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

Fix multiple bugs in arrow.get() tzinfo kwarg handling #968

Merged
merged 6 commits into from
May 3, 2021

Conversation

systemcatch
Copy link
Collaborator

@systemcatch systemcatch commented Apr 29, 2021

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

The tzinfo kwarg should now be handled correctly rather than being dropped.

fixes #944

@codecov
Copy link

codecov bot commented Apr 29, 2021

Codecov Report

Merging #968 (4d65c00) into master (fe1aaae) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #968   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2036      2036           
  Branches       328       328           
=========================================
  Hits          2036      2036           
Impacted Files Coverage Δ
arrow/factory.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe1aaae...4d65c00. Read the comment docs.

@jadchaar
Copy link
Member

LGTM, but I think this is a more widespread issue @systemcatch. We should be passing along the tz object in all of these other factory methods as well:

arrow/arrow/factory.py

Lines 234 to 247 in 08705bc

elif isinstance(arg, Arrow):
return self.type.fromdatetime(arg.datetime)
# (datetime) -> from datetime.
elif isinstance(arg, datetime):
return self.type.fromdatetime(arg)
# (date) -> from date.
elif isinstance(arg, date):
return self.type.fromdate(arg)
# (tzinfo) -> now, @ tzinfo.
elif isinstance(arg, dt_tzinfo):
return self.type.now(arg)
(and maybe more!). Weird this has not come up until now, but we may need to apply this change to a bunch of factory methods. Thoughts?

@systemcatch
Copy link
Collaborator Author

Hey @jadchaar I agree with you on the Arrow one to avoid this bug below.

>>> arw=arrow.Arrow(2021, 4, 29, 22, 7, tzinfo="America/Chicago")
>>> arw
<Arrow [2021-04-29T22:07:00-05:00]>
>>> arrow.get(arw, tzinfo="Europe/London")
<Arrow [2021-04-29T22:07:00-05:00]>

However the date factory doesn't need it I think and all the others seem correct.

@systemcatch systemcatch changed the title Fix bug in factory.get(datetime, tzinfo=...) Fix multiple bugs in arrow.get() tzinfo kwarg handling May 1, 2021
@jadchaar
Copy link
Member

jadchaar commented May 1, 2021

@systemcatch I made a few tweaks to comments and made the tzinfo kwarg explicit for the get() factory method in 4d65c00. Let me know what you think!

@systemcatch
Copy link
Collaborator Author

Looks good to me Jad, feel free to merge if you're happy with everything.

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 06fe693 into arrow-py:master May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arrow.get(datetime.now()).humanize() == "6 hours ago"
2 participants