I had been running a script using meteostat fine, but it looks like perhaps something has broken in the code? I debugged by trying to run this sample script from the documentation.
`# Import Meteostat library and dependencies
from datetime import datetime
import matplotlib.pyplot as plt
from meteostat import Point, Daily
Set time period
start = datetime(2018, 1, 1)
end = datetime(2018, 12, 31)
Create Point for Vancouver, BC
vancouver = Point(49.2497, -123.1193, 70)
Get daily data for 2018
data = Daily(vancouver, start, end)
data = data.fetch()
Plot line chart including average, minimum and maximum temperature
data.plot(y=['tavg', 'tmin', 'tmax'])
plt.show()`
I'm running this in a JupterLab Notebook. This is the error it gives me:
`---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/anaconda/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2897 try:
-> 2898 return self._engine.get_loc(casted_key)
2899 except KeyError as err:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'distance'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
/usr/local/anaconda/lib/python3.6/site-packages/pandas/core/generic.py in _set_item(self, key, value)
3575 try:
-> 3576 loc = self._info_axis.get_loc(key)
3577 except KeyError:
/usr/local/anaconda/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2899 except KeyError as err:
-> 2900 raise KeyError(key) from err
2901
KeyError: 'distance'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
in
12
13 # Get daily data for 2018
---> 14 data = Daily(vancouver, start, end)
15 data = data.fetch()
16
/usr/local/anaconda/lib/python3.6/site-packages/meteostat/daily.py in init(self, loc, start, end, model)
238 self.stations = loc.index
239 elif isinstance(loc, Point):
--> 240 stations = loc.get_stations('hourly', start, end)
241 self.stations = stations.index
242 else:
/usr/local/anaconda/lib/python3.6/site-packages/meteostat/point.py in get_stations(self, granularity, start, end)
70 # Get nearby weather stations
71 stations = Stations()
---> 72 stations = stations.nearby(self.lat, self.lon, self.radius)
73
74 # Guess altitude if not set
/usr/local/anaconda/lib/python3.6/site-packages/meteostat/stations.py in nearby(self, lat, lon, radius)
161 # Get distance for each stationsd
162 temp.stations['distance'] = temp.stations.apply(
--> 163 lambda station: distance(station, [lat, lon]), axis=1)
164
165 # Filter by radius
/usr/local/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in setitem(self, key, value)
3042 else:
3043 # set column
-> 3044 self._set_item(key, value)
3045
3046 def _setitem_slice(self, key: slice, value):
/usr/local/anaconda/lib/python3.6/site-packages/pandas/core/frame.py in _set_item(self, key, value)
3119 self._ensure_valid_index(value)
3120 value = self._sanitize_column(key, value)
-> 3121 NDFrame._set_item(self, key, value)
3122
3123 # check if we are modifying a copy
/usr/local/anaconda/lib/python3.6/site-packages/pandas/core/generic.py in _set_item(self, key, value)
3577 except KeyError:
3578 # This item wasn't present, just insert at end
-> 3579 self._mgr.insert(len(self._info_axis), key, value)
3580 return
3581
/usr/local/anaconda/lib/python3.6/site-packages/pandas/core/internals/managers.py in insert(self, loc, item, value, allow_duplicates)
1196 value = _safe_reshape(value, (1,) + value.shape)
1197
-> 1198 block = make_block(values=value, ndim=self.ndim, placement=slice(loc, loc + 1))
1199
1200 for blkno, count in _fast_count_smallints(self.blknos[loc:]):
/usr/local/anaconda/lib/python3.6/site-packages/pandas/core/internals/blocks.py in make_block(values, placement, klass, ndim, dtype)
2742 values = DatetimeArray._simple_new(values, dtype=dtype)
2743
-> 2744 return klass(values, ndim=ndim, placement=placement)
2745
2746
/usr/local/anaconda/lib/python3.6/site-packages/pandas/core/internals/blocks.py in init(self, values, placement, ndim)
2398 values = np.array(values, dtype=object)
2399
-> 2400 super().init(values, ndim=ndim, placement=placement)
2401
2402 @Property
/usr/local/anaconda/lib/python3.6/site-packages/pandas/core/internals/blocks.py in init(self, values, placement, ndim)
129 if self._validate_ndim and self.ndim and len(self.mgr_locs) != len(self.values):
130 raise ValueError(
--> 131 f"Wrong number of items passed {len(self.values)}, "
132 f"placement implies {len(self.mgr_locs)}"
133 )
ValueError: Wrong number of items passed 9, placement implies 1`