Skip to content

Commit dee4399

Browse files
committed
Meteostat 1.4.2
1 parent a295c2d commit dee4399

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

examples/normals/point.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
vancouver = Point(49.2497, -123.1193, 70)
1616

1717
# Get normals
18-
data = Normals(vancouver, (1961, 1990))
18+
data = Normals(vancouver, 1961, 1990)
1919
data = data.fetch()
2020

2121
# Plot chart

meteostat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"""
1313

1414
__appname__ = 'meteostat'
15-
__version__ = '1.4.1'
15+
__version__ = '1.4.2'
1616

1717
from .interface.stations import Stations
1818
from .interface.point import Point

meteostat/interface/normals.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ class Normals(Base):
3333
# The list of weather Stations
3434
_stations: pd.Index = None
3535

36-
# The period
37-
_period: Union[int, str] = 'auto'
36+
# The first year of the period
37+
_start: int = None
38+
39+
# The last year of the period
40+
_end: int = None
3841

3942
# The data frame
4043
_data: pd.DataFrame = pd.DataFrame()
@@ -108,14 +111,14 @@ def _load(
108111
df.to_pickle(path)
109112

110113
# Filter time period and append to DataFrame
111-
if df.index.size > 0 and self._period not in ['auto', 'all']:
114+
if df.index.size > 0 and self._end:
112115

113116
# Get time index
114117
end = df.index.get_level_values('end')
115118

116119
# Filter & append
117120
self._data = self._data.append(
118-
df.loc[end == self._period])
121+
df.loc[end == self._end])
119122

120123
else:
121124

@@ -206,18 +209,20 @@ def _resolve_point(
206209
def __init__(
207210
self,
208211
loc: Union[pd.DataFrame, Point, list, str],
209-
period: Union[tuple, str] = 'auto'
212+
start: int = None,
213+
end: int = None
210214
) -> None:
211215

212216
# Set list of weather stations
213217
if isinstance(loc, pd.DataFrame):
214218
self._stations = loc.index
215219

216220
elif isinstance(loc, Point):
217-
if isinstance(period, tuple):
218-
start = datetime(period[0], 1, 1)
219-
end = datetime(period[1], 12, 31)
220-
stations = loc.get_stations('monthly', start, end)
221+
if start and end:
222+
stations = loc.get_stations(
223+
'monthly', datetime(
224+
start, 1, 1), datetime(
225+
end, 12, 31))
221226
else:
222227
stations = loc.get_stations()
223228

@@ -229,8 +234,9 @@ def __init__(
229234

230235
self._stations = pd.Index(loc)
231236

232-
# The reference period
233-
self._period = period[1] if isinstance(period, tuple) else period
237+
# Set period
238+
self._start = start
239+
self._end = end
234240

235241
# Get data for all weather stations
236242
self._get_data()
@@ -239,11 +245,6 @@ def __init__(
239245
if isinstance(loc, Point):
240246
self._resolve_point(loc.method, stations, loc.alt, loc.adapt_temp)
241247

242-
# Aggregate if period is auto
243-
if self._period == 'auto' and self._data.index.size > 0:
244-
self._data = self._data.groupby(
245-
level=['station', 'month']).agg('last')
246-
247248
# Clear cache
248249
if self.max_age > 0:
249250
self.clear_cache()
@@ -265,7 +266,7 @@ def fetch(self) -> pd.DataFrame:
265266
temp = temp.reset_index(level='station', drop=True)
266267

267268
# Remove start & end year if period is set
268-
if isinstance(self._period, int) and 'start' in temp.index.names:
269+
if self._start and self._end:
269270
temp = temp.reset_index(level='start', drop=True)
270271
temp = temp.reset_index(level='end', drop=True)
271272

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Setup
1616
setup(
1717
name='meteostat',
18-
version='1.4.1',
18+
version='1.4.2',
1919
author='Meteostat',
2020
author_email='[email protected]',
2121
description='Access and analyze historical weather and climate data with Python.',

0 commit comments

Comments
 (0)