fitnr / convertdate

Utils for converting between date formats and calculating holidays
MIT License
47 stars 24 forks source link

hebrew.to_jd_gregorianyear(...) cannot unpack non-iterable float object #38

Closed carma31 closed 3 years ago

carma31 commented 4 years ago

Hi,

I am using fbprophet 0.7.1 and holidays 0.10.3 but since Nov 8th I am getting an error when trying to add holidays from Israel. In holidays it is used hebrew module from convertdate.

`When 30 # Passover 31 name = "Passover I" ---> 32 year, month, day = hebrew.to_jd_gregorianyear(year, hebrew.NISAN, 14) 33 passover_start_dt = date(year, month, day) 34 self[passover_start_dt] = name + ' - Eve'

TypeError: cannot unpack non-iterable float object`

¿Is this related to last convertdate 2.3 release of Nov 7th?

dr-prodigy commented 4 years ago

Hi, in fact, this seems related to the change of hebrew.to_jd_gregorianyear signature. I'm currently looking for a fix on python-holidays for this new behaviour. open issue Although a subsequent call to gregorian.from_jd as gregorian.from_jd(hebrew.to_jd_gregorianyear (..)) seems to me the easiest way to revert to the previously returned format (year, month, day) I noticed some differences (possibly issues?) in the date calculation results (ie: current results don't match the existing unit test expectations) so I'm currently in standby, keeping back convertdate to v2.2.0.

Any update available on this?

dr-prodigy commented 4 years ago

Hi, any updates / thoughts on this @fitnr ? Thx

fitnr commented 4 years ago

Please post the smallest possible code snippet to reproduce the error. I can’t make head or tails of what’s in the original comment

dorgol commented 3 years ago

I reversed the code to an older version:

def to_jd_gregorianyear(gregorianyear, hebrew_month, hebrew_day):
      for y in (gregorianyear + HEBREW_YEAR_OFFSET, gregorianyear + HEBREW_YEAR_OFFSET + 1):
          jd = to_jd(y, hebrew_month, hebrew_day)
          gd = gregorian.from_jd(jd)
          if gd[0] == gregorianyear:
              break
          else:
              gd = None

    if not gd:  # should never occur, but just incase...
        raise ValueError("Could not determine gregorian year")

    # tuple: (y, m, d)
    return (gd[0], gd[1], gd[2])

instead of:

def to_jd_gregorianyear(gregorianyear, hebrew_month, hebrew_day):

    for y in (gregorianyear + HEBREW_YEAR_OFFSET, gregorianyear + HEBREW_YEAR_OFFSET + 1):
        jd = to_jd(y, hebrew_month, hebrew_day)
        gd = gregorian.from_jd(jd)
        if gd[0] == gregorianyear:
            break

        jd = None

    if not jd:  # should never occur, but just incase...
        raise ValueError("Could not determine gregorian year")

    return gregorian.to_jd(gd[0], gd[1], gd[2])

The problem is that gregorian.to_jd returns a number instead of a tuple.

fitnr commented 3 years ago

Yes, this method changed. The earlier version didn't adequately support other functions, especially the holiday library.