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

TypeError: unsupported type for timedelta weeks component: numpy.int64 #9

Open
gla-seva opened this issue Oct 10, 2021 · 4 comments
Open

Comments

@gla-seva
Copy link

gla-seva commented Oct 10, 2021

/usr/local/lib/python3.6/dist-packages/isoweek.py in __add__(self, other)
    162         if isinstance(other, timedelta):
    163             other = other.days // 7
--> 164         return self.__class__.fromordinal(self.toordinal() + other)
    165 
    166     def __sub__(self, other):

/usr/local/lib/python3.6/dist-packages/isoweek.py in toordinal(self)
    135     def toordinal(self):
    136         """Return the proleptic Gregorian ordinal the week, where January 1 of year 1 starts the first week."""
--> 137         return self.monday().toordinal() // 7 + 1
    138 
    139     def replace(self, year=None, week=None):

/usr/local/lib/python3.6/dist-packages/isoweek.py in monday(self)
     98     def monday(self):
     99         """Return the first day of the week as a date object"""
--> 100         return self.day(0)
    101 
    102     def tuesday(self):

/usr/local/lib/python3.6/dist-packages/isoweek.py in day(self, num)
     94         """Return the given day of week as a date object.  Day 0 is the Monday."""
     95         d = date(self.year, 1, 4)  # The Jan 4th must be in week 1 according to ISO
---> 96         return d + timedelta(weeks=self.week-1, days=-d.weekday() + num)
     97 
     98     def monday(self):

TypeError: unsupported type for timedelta weeks component: numpy.int64
@extrospective
Copy link

issues related to numpy compatibility make it difficult to use this library.

Although my actual bug refers to numpy.int32:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-954a1fcde394> in <module>
      8             continue
      9         dw = Week(year, i)
---> 10         d = dw.monday()
     11         record = [f'{year}-{str(i).zfill(2)}', year, i, d]
     12         records.append(record)

d:\Anaconda3\envs\py39\lib\site-packages\isoweek.py in monday(self)
     98     def monday(self):
     99         """Return the first day of the week as a date object"""
--> 100         return self.day(0)
    101 
    102     def tuesday(self):

d:\Anaconda3\envs\py39\lib\site-packages\isoweek.py in day(self, num)
     94         """Return the given day of week as a date object.  Day 0 is the Monday."""
     95         d = date(self.year, 1, 4)  # The Jan 4th must be in week 1 according to ISO
---> 96         return d + timedelta(weeks=self.week-1, days=-d.weekday() + num)
     97 
     98     def monday(self):

TypeError: unsupported type for timedelta weeks component: numpy.int32

@extrospective
Copy link

Wrapping the timedelta weeks in int seems to fix one issue

approximately:

         timedelta(weeks=int(dw.week-1), days=-d.weekday())

leaving this breadcrumb in case someone revisits this library, or an end user needs to borrow a few lines of code themselves to work around a bug.

@pmahuzieru
Copy link

As @extrospective did, I also overcame this problem by casting my numpy.int64 week number like this: isoweek.Week(year, int(week_num)), for when I use the constructor.

@Olukeye
Copy link

Olukeye commented Feb 15, 2023

You can also try this method as it worked for me:
expireIn = datetime.utcnow() + timedelta(minutes=int(ACCESS_TOKEN_EXPIRE_MINUTE))

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

4 participants