ValueError when importing unicode_literals from __future__

Bug #1588198 reported by Hugo on 2016-06-02
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Simon Kennedy

Bug Description

Windows 7, Python 2.7.11, Astral 1.1

This code works (from the example code at ):

#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
# from __future__ import unicode_literals
import datetime
from astral import Astral # pip install astral

city_name = 'London'
a = Astral()
a.solar_depression = 'civil'
city = a[city_name]

print('Information for %s/%s\n' % (city_name, city.region))

timezone = city.timezone
print('Timezone: %s' % timezone)

print(' Latitude: %.02f; Longitude: %.02f\n' % \
    (city.latitude, city.longitude))

sun = city.sun(, 4, 22), local=True)
print('Dawn: %s' % str(sun['dawn']))
print('Sunrise: %s' % str(sun['sunrise']))
print('Noon: %s' % str(sun['noon']))
print('Sunset: %s' % str(sun['sunset']))
print('Dusk: %s' % str(sun['dusk']))

Information for London/England

Timezone: Europe/London
 Latitude: 51.50; Longitude: -0.12

Dawn: 2009-04-22 05:12:06+01:00
Sunrise: 2009-04-22 05:48:46+01:00
Noon: 2009-04-22 12:58:56+01:00
Sunset: 2009-04-22 20:09:00+01:00
Dusk: 2009-04-22 20:45:39+01:00


But uncommenting `from __future__ import unicode_literals` it gives:
Traceback (most recent call last):
  File "", line 10, in <module>
    a.solar_depression = 'civil'
  File "C:\Python27\lib\site-packages\", line 1493, in solar_depression
    self._depression = float(depression)
ValueError: could not convert string to float: civil

Hugo (hugovk) wrote :

One fix:

    def solar_depression(self, depression):
        if isinstance(depression, str):

    def solar_depression(self, depression):
        if isinstance(depression, str) or isinstance(depression, unicode):


Another fix:

Add as first import:
from __future__ import unicode_literals

In latitude(self, latitude), longitude(self, longitude), solar_depression(self, depression):

        if isinstance(depression, str):

        if isinstance(depression, unicode):


For both, there may be other similar changes to make elsewhere in the code; tests should find them.

Changed in astral:
status: New → Confirmed
importance: Undecided → High
assignee: nobody → Simon Kennedy (sffjunkie)
Changed in astral:
status: Confirmed → Triaged
Changed in astral:
status: Triaged → Fix Committed
Hugo (hugovk) wrote :

Please let me know when this has been released.

Changed in astral:
status: Fix Committed → Fix Released
Hugo (hugovk) wrote :

Thanks, confirmed fixed with Astral 1.2.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers