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

Incompatiable with new arrow #32

Closed
jonringer opened this issue Dec 22, 2019 · 2 comments
Closed

Incompatiable with new arrow #32

jonringer opened this issue Dec 22, 2019 · 2 comments

Comments

@jonringer
Copy link

with arrow==0.15.4, the tests throw the following error:

_____________________________ test_datetime_parser _____________________________

    def test_datetime_parser():
        now = arrow.now()

        ts_tuples = [
            ("10 minutes ago", lambda x: x.replace(minutes=-10, microsecond=0, tzinfo='local')),
            ("1 day ago", lambda x: x.replace(days=-1, microsecond=0, tzinfo='local')),
            ("yesterday midnight", lambda x: x.replace(days=-1, hour=0, minute=0, second=0, microsecond=0, tzinfo='local')),
            ("1986-04-24 00:51:24+02:00", lambda x: arrow.get("1986-04-24 00:51:24+02:00")),
            ("2001-01-01 01:01:01", lambda x: arrow.get("2001-01-01 01:01:01").replace(tzinfo="local")),
            (now, lambda x: now)]

        for (s, ts) in ts_tuples:
>           assert datetime_parser(s) == ts(arrow.now())

tests/test_dateutils.py:25:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_dateutils.py:17: in <lambda>
    ("10 minutes ago", lambda x: x.replace(minutes=-10, microsecond=0, tzinfo='local')),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <Arrow [2019-12-22T18:24:15.958968+00:00]>
kwargs = {'microsecond': 0, 'minutes': -10, 'tzinfo': 'local'}
absolute_kwargs = {}, key = 'minutes', value = -10

    def replace(self, **kwargs):
        """ Returns a new :class:`Arrow <arrow.arrow.Arrow>` object with attributes updated
        according to inputs.

        Use property names to set their value absolutely::

            >>> import arrow
            >>> arw = arrow.utcnow()
            >>> arw
            <Arrow [2013-05-11T22:27:34.787885+00:00]>
            >>> arw.replace(year=2014, month=6)
            <Arrow [2014-06-11T22:27:34.787885+00:00]>

        You can also replace the timezone without conversion, using a
        :ref:`timezone expression <tz-expr>`::

            >>> arw.replace(tzinfo=tz.tzlocal())
            <Arrow [2013-05-11T22:27:34.787885-07:00]>

        """

        absolute_kwargs = {}

        for key, value in kwargs.items():

            if key in self._ATTRS:
                absolute_kwargs[key] = value
            elif key in ["week", "quarter"]:
                raise AttributeError("setting absolute {} is not supported".format(key))
            elif key != "tzinfo":
>               raise AttributeError('unknown attribute: "{}"'.format(key))
E               AttributeError: unknown attribute: "minutes"
@systemcatch
Copy link

arrow was changed (way before 0.15.4) to stop replace being used to shift the entire object.

This changes only the second attribute, nothing else.

arw=arrow.utcnow()
arw_later=arw.replace(second=37)

To fix your tests use the shift method which will update the entire object.

arw=arrow.utcnow()
arw_later=arw.shift(seconds=+37)

I'd recommend upping your pinned arrow versions (see changelog) if possible as 0.5.4 is very old, note that 0.15.0+ have breaking changes to do with parsing.

@valentin-krasontovitsch
Copy link
Collaborator

i think it might be fixed now - the tests pass, at least with arrow 0.15.5 - thanks for the pointers regarding the necessary changes!

My impression of the changes is that one must use replace when changing the locale and setting a value, like microsecond=0, while shift is good to use for days=+1, as you describe. but i don't claim to really get arrow... let's hope that this holds up.

will merge soon, i think, and cut a new release - which i sadly still cannot publish on pip, but hopefully that will be fixed soon as well!

ahmedsajid pushed a commit to ahmedsajid/bonfire that referenced this issue Dec 13, 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

No branches or pull requests

3 participants