Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpolation error "ValueError: The name station occurs multiple times, use a level number" #130

Closed
aldder opened this issue Jul 19, 2023 · 3 comments

Comments

@aldder
Copy link

aldder commented Jul 19, 2023

Hello, If you try to run the code in the interpolation documentation section it will output the following error:

some infos:
python version: 3.11.4
meteostat: 1.6.5
pandas: 2.0.3

CODE:

from datetime
 import datetime
from meteostat import Stations, Hourly

stations = Stations()
stations = stations.nearby(49.2497, -123.1193)
station = stations.fetch(1)

start = datetime(2018, 1, 1)
end = datetime(2018, 12, 31, 23, 59)

data = Hourly(station, start=start, end=end)
data = data.normalize()
data = data.interpolate()
data = data.fetch()

print(data)

OUTPUT:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], line 14
     12 data = data.normalize()
     13 data = data.interpolate()
---> 14 data = data.fetch()
     16 print(data)

File [c:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\meteostat\series\fetch.py:25](file:///C:/Users/user/AppData/Local/Programs/Python/Python311/Lib/site-packages/meteostat/series/fetch.py:25), in fetch(self)
     23 # Remove station index if it's a single station
     24 if len(self._stations) == 1 and "station" in temp.index.names:
---> 25     temp = temp.reset_index(level="station", drop=True)
     27 # Return data frame
     28 return temp

File [c:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\frame.py:6162](file:///C:/Users/user/AppData/Local/Programs/Python/Python311/Lib/site-packages/pandas/core/frame.py:6162), in DataFrame.reset_index(self, level, drop, inplace, col_level, col_fill, allow_duplicates, names)
   6160 if not isinstance(level, (tuple, list)):
   6161     level = [level]
-> 6162 level = [self.index._get_level_number(lev) for lev in level]
   6163 if len(level) < self.index.nlevels:
   6164     new_index = self.index.droplevel(level)

File [c:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\frame.py:6162](file:///C:/Users/user/AppData/Local/Programs/Python/Python311/Lib/site-packages/pandas/core/frame.py:6162), in (.0)
   6160 if not isinstance(level, (tuple, list)):
   6161     level = [level]
-> 6162 level = [self.index._get_level_number(lev) for lev in level]
   6163 if len(level) < self.index.nlevels:
   6164     new_index = self.index.droplevel(level)

File [c:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\multi.py:1484](file:///C:/Users/user/AppData/Local/Programs/Python/Python311/Lib/site-packages/pandas/core/indexes/multi.py:1484), in MultiIndex._get_level_number(self, level)
   1482 count = self.names.count(level)
   1483 if (count > 1) and not is_integer(level):
-> 1484     raise ValueError(
   1485         f"The name {level} occurs multiple times, use a level number"
   1486     )
   1487 try:
   1488     level = self.names.index(level)

ValueError: The name station occurs multiple times, use a level number
@peterspat
Copy link

Unfortunately, I have the same problem and can confirm the issue for the Python and packages version.

@BrushXue
Copy link

I have the same problem with the same version.

clampr added a commit that referenced this issue Sep 26, 2023
clampr added a commit that referenced this issue Sep 26, 2023
* Fix Pandas version (#130)

* Avoid querying future data (#132)

* Accessing the correct column for weighted average (#131)

Co-authored-by: Jan <jan@getml.com>

* Update version

* Use Python 3.11 for tests

* Remove unused import

* Silence warning

---------

Co-authored-by: Jan Meyer <janmeyer1986@web.de>
Co-authored-by: Jan <jan@getml.com>
Co-authored-by: bram-tv
@clampr
Copy link
Member

clampr commented Sep 26, 2023

Hi all,

It seems like Meteostat doesn't support Pandas v2. Version 1.6.6 has the correct dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants