g-battaglia / kerykeion

Data driven Astrology 💫
Kerykeion is a python library for astrology. It can generate SVG charts and extract all data about a birthchart, a synastry chart and a transit chart.
https://kerykeion.net
GNU Affero General Public License v3.0
297 stars 103 forks source link

AmbiguousTimeError with some datetimes #96

Closed to175 closed 1 month ago

to175 commented 9 months ago

Hello,

I have this issue both with version 4.2.4 and 3.4.1

It works with 1:30 but not with 2:30 for example because of wierd error...

Code

from kerykeion import AstrologicalSubject
kanye = AstrologicalSubject("Kanye", 1983, 9, 25, 1, 30, "Paris", "France")
print(1,repr(kanye))

from kerykeion import AstrologicalSubject
kanye = AstrologicalSubject("Kanye", 1983, 9, 25, 2, 30, "Paris", "France")
print(2,repr(kanye))

Output

1 Astrological data for: Kanye, 1983-09-24 23:30:00+00:00 UTC
Birth location: Paris, Lat 48.85341, Lon 2.3488

Traceback (most recent call last):
  File "C:\Users\user\OneDrive\Documents\Python Scripts\testkerykeion4\test.py", line 6, in <module>
    kanye = AstrologicalSubject("Kanye", 1983, 9, 25, 2, 30, "Paris", "France")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\OneDrive\Documents\Python Scripts\testkerykeion4\myvenv\Lib\site-packages\kerykeion\astrological_subject.py", line 192, in __init__
    self._get_utc()
  File "C:\Users\user\OneDrive\Documents\Python Scripts\testkerykeion4\myvenv\Lib\site-packages\kerykeion\astrological_subject.py", line 256, in _get_utc
    local_datetime = local_time.localize(naive_datetime, is_dst=None)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\OneDrive\Documents\Python Scripts\testkerykeion4\myvenv\Lib\site-packages\pytz\tzinfo.py", line 363, in localize
    raise AmbiguousTimeError(dt)
pytz.exceptions.AmbiguousTimeError: 1983-09-25 02:30:00

Same issue with 3.4.1 image

g-battaglia commented 9 months ago

Hi, the error is correct, that time technically doesn't exist. Since the winter time started at 2 o clock and 2 o clock bacame 3 o clock there never was 2.30 in 1983 in France. Here a reference:

https://www.timeanddate.com/time/change/france/paris-department?year=1983

Hope I was enough clear!

to175 commented 9 months ago

Oh I understand now, thanks! However my date is 25 Sept and I can see on the link you shared that we are in the second case "Back 1 hour" so we are supposed to be twice on 2:55

So the time can be ambiguous because we don't know if we are in the first or the second 2:55 but this time has existed! So what to do in this case please? @g-battaglia We should have some automatic thing to pick either first or second but not run into this error

theriftlab commented 7 months ago

@g-battaglia this seems easily solvable since line 254 of astrological_subject.py is already explicitly setting is_dst to None:

local_datetime = local_time.localize(naive_datetime, is_dst=None)

If you simply add is_dst as a named argument to the constructor and pass this through to the above call to localize instead of None then the user can decide which side of Daylight Savings their time belongs to & the problem should be solved.

g-battaglia commented 2 months ago

Hey @theriftlab @to175, can you check if now this issue is fixed it and write here if now it's ok? Thanks

g-battaglia commented 1 month ago

Fixed in v4.13.0