openeemeter/eeweather

SQLAlchemy requires a string schema argument, not Engine object

jup014 opened this issue · 4 comments

jup014 commented

Describe the bug
When I try to fetch weather data as follows, sqlalchemy gives me the following exception:

import eeweather

ranked_stations = eeweather.rank_stations(35, -95)
station, warnings = eeweather.select_station(ranked_stations)

start_date = datetime.datetime(2016, 6, 1, tzinfo=pytz.UTC)
end_date = datetime.datetime(2017, 9, 15, tzinfo=pytz.UTC)
station.load_isd_hourly_temp_data(start=start_date, end=end_date)

The exception stacktrace:

---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
[<ipython-input-83-3690950de639>](https://localhost:8080/#) in <cell line: 3>()
      1 start_date = datetime.datetime(2016, 6, 1, tzinfo=pytz.UTC)
      2 end_date = datetime.datetime(2017, 9, 15, tzinfo=pytz.UTC)
----> 3 station.load_isd_hourly_temp_data(start=start_date, end=end_date)

8 frames
[/usr/local/lib/python3.10/dist-packages/eeweather/stations.py](https://localhost:8080/#) in load_isd_hourly_temp_data(self, start, end, read_from_cache, write_to_cache, fetch_from_web, error_on_missing_years)
   1449             Whether or not to write newly loaded data to cache.
   1450         """
-> 1451         return load_isd_hourly_temp_data(
   1452             self.usaf_id,
   1453             start,

[/usr/local/lib/python3.10/dist-packages/eeweather/stations.py](https://localhost:8080/#) in load_isd_hourly_temp_data(usaf_id, start, end, read_from_cache, write_to_cache, error_on_missing_years, fetch_from_web)
    843                 pass
    844     else:
--> 845         data = [
    846             load_isd_hourly_temp_data_cached_proxy(
    847                 usaf_id,

[/usr/local/lib/python3.10/dist-packages/eeweather/stations.py](https://localhost:8080/#) in <listcomp>(.0)
    844     else:
    845         data = [
--> 846             load_isd_hourly_temp_data_cached_proxy(
    847                 usaf_id,
    848                 year,

[/usr/local/lib/python3.10/dist-packages/eeweather/stations.py](https://localhost:8080/#) in load_isd_hourly_temp_data_cached_proxy(usaf_id, year, read_from_cache, write_to_cache, fetch_from_web)
    713 ):
    714     # take from cache?
--> 715     data_ok = validate_isd_hourly_temp_data_cache(usaf_id, year)
    716 
    717     if not fetch_from_web and not data_ok:

[/usr/local/lib/python3.10/dist-packages/eeweather/stations.py](https://localhost:8080/#) in validate_isd_hourly_temp_data_cache(usaf_id, year)
    482 def validate_isd_hourly_temp_data_cache(usaf_id, year):
    483     key = get_isd_hourly_temp_data_cache_key(usaf_id, year)
--> 484     store = eeweather.connections.key_value_store_proxy.get_store()
    485 
    486     # fail if no key

[/usr/local/lib/python3.10/dist-packages/eeweather/connections.py](https://localhost:8080/#) in get_store(self)
    110     def get_store(self):  # pragma: no cover
    111         if self._store is None:
--> 112             self._store = KeyValueStore()
    113         return self._store
    114 

[/usr/local/lib/python3.10/dist-packages/eeweather/cache.py](https://localhost:8080/#) in __init__(self, url)
     51         if not has_sqlalchemy:  # pragma: no cover
     52             raise ImportError("KeyValueStore requires sqlalchemy.")
---> 53         self._prepare_db(url)
     54 
     55     def __repr__(self):

[/usr/local/lib/python3.10/dist-packages/eeweather/cache.py](https://localhost:8080/#) in _prepare_db(self, url)
     73 
     74         eng = create_engine(url)
---> 75         metadata = MetaData(eng)
     76 
     77         tbl_items = Table(

[/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/schema.py](https://localhost:8080/#) in __init__(self, schema, quote_schema, naming_convention, info)
   5438         """
   5439         if schema is not None and not isinstance(schema, str):
-> 5440             raise exc.ArgumentError(
   5441                 "expected schema argument to be a string, "
   5442                 f"got {type(schema)}."

ArgumentError: expected schema argument to be a string, got <class 'sqlalchemy.engine.base.Engine'>.

The cause is at line 73 in /eeweather/cache.py:

eng = create_engine(url)

(The stacktrace above shows the line number 74, but the actual code's line number is 73)

To Reproduce
The codes in the description section explains pretty well.

Expected behavior
The weather should be fetched.

Desktop (please complete the following information):

  • OS: Google Colab

Additional context
eeweather==0.3.24

I just got this problem as well. The package is not compatible with new pandas and sqlalchemy. It works for me with sqlalchemy==1.4 and pandas==1.5. Hope the answer didn't come too late.

I fixed in this PR #87

This should now be fixed in the newest version on pypi.

jup014 commented

Great! I just checked and it works! Thank you.