Skip to content

Commit 7acfc29

Browse files
authored
Merge pull request #39 from wind-python/fix/bug_#38
Fixes #38 by adapting csv reading to pandas API change
2 parents 4e22126 + 400ed99 commit 7acfc29

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

example/modelchain_example.ipynb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,17 @@
122122
" os.path.dirname(__file__))[0], 'example')\n",
123123
" file = os.path.join(kwargs['datapath'], filename)\n",
124124
" # read csv file \n",
125-
" weather_df = pd.read_csv(file, index_col=0, header=[0, 1])\n",
125+
" weather_df = pd.read_csv(\n",
126+
" file, index_col=0, header=[0, 1],\n",
127+
" date_parser=lambda idx: pd.to_datetime(idx, utc=True))\n",
126128
" # change type of index to datetime and set time zone\n",
127-
" weather_df.index = pd.to_datetime(weather_df.index).tz_localize(\n",
128-
" 'UTC').tz_convert('Europe/Berlin')\n",
129+
" weather_df.index = pd.to_datetime(weather_df.index).tz_convert(\n",
130+
" 'Europe/Berlin')\n",
129131
" # change type of height from str to int by resetting columns\n",
130132
" weather_df.columns = [weather_df.axes[1].levels[0][\n",
131-
" weather_df.axes[1].labels[0]],\n",
133+
" weather_df.axes[1].codes[0]],\n",
132134
" weather_df.axes[1].levels[1][\n",
133-
" weather_df.axes[1].labels[1]].astype(int)]\n",
135+
" weather_df.axes[1].codes[1]].astype(int)]\n",
134136
" return weather_df\n",
135137
"\n",
136138
"\n",

example/modelchain_example.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ def get_weather_data(filename='weather.csv', **kwargs):
7272
os.path.dirname(__file__))[0], 'example')
7373
file = os.path.join(kwargs['datapath'], filename)
7474
# read csv file
75-
weather_df = pd.read_csv(file, index_col=0, header=[0, 1])
75+
weather_df = pd.read_csv(
76+
file, index_col=0, header=[0, 1],
77+
date_parser=lambda idx: pd.to_datetime(idx, utc=True))
7678
# change type of index to datetime and set time zone
77-
weather_df.index = pd.to_datetime(weather_df.index).tz_localize(
78-
'UTC').tz_convert('Europe/Berlin')
79+
weather_df.index = pd.to_datetime(weather_df.index).tz_convert(
80+
'Europe/Berlin')
7981
# change type of height from str to int by resetting columns
8082
weather_df.columns = [weather_df.axes[1].levels[0][
81-
weather_df.axes[1].labels[0]],
83+
weather_df.axes[1].codes[0]],
8284
weather_df.axes[1].levels[1][
83-
weather_df.axes[1].labels[1]].astype(int)]
85+
weather_df.axes[1].codes[1]].astype(int)]
8486
return weather_df
8587

8688

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ def read(fname):
1616
'windpowerlib': [os.path.join('data', '*.csv')]},
1717
long_description=read('README.rst'),
1818
zip_safe=False,
19-
install_requires=['pandas >= 0.19.1',
19+
install_requires=['pandas >= 0.19.1, < 0.25 ',
2020
'requests'])

0 commit comments

Comments
 (0)