EnergieID / entsoe-py

Python client for the ENTSO-E API (european network of transmission system operators for electricity)
MIT License
425 stars 187 forks source link

KeyError: 'start' #12

Closed alexhaikel closed 4 years ago

alexhaikel commented 6 years ago

Hello,

I am trying to use the ENTSOE package to download gas burn in CCGTs in Germany. I get the following error when I try to run the query below

de_ccgt=client.query_generation(country_code, start, end, psr_type=None)

error

Traceback (most recent call last):

  File "<ipython-input-67-2c98097570c2>", line 1, in <module>
    de_ccgt=client.query_generation(country_code, start, end, psr_type=None)

  File "C:\Users\ah76671\AppData\Local\Continuum\anaconda2\lib\site-packages\entsoe\entsoe.py", line 393, in year_wrapper
    start = kwargs.pop('start')

KeyError: 'start'

Any idea how to solve this? Thanks for your help

JrtPec commented 6 years ago

Thanks for spotting the bug!

It tries to retrieve the parameter "start" as a keyword argument, so passing these parameters as positional arguments doesn't work:

country_code = 'DE'
start = pd.Timestamp('20181020', tz='Europe/Berlin')
end = pd.Timestamp('20181024', tz='Europe/Berlin')

client.query_generation(country_code, start, end)

but passing them as keyword arguments does:

client.query_generation(country_code, start=start, end=end)

I will try to figure out a fix, but in the meantime you can just use keyword arguments.

JrtPec commented 6 years ago

I sort of "fixed" it by enforcing the arguments to be keyworded (see 9b3cce8).

If you try it now you get a more explicit error: TypeError: year_wrapper() missing 2 required keyword-only arguments: 'start' and 'end'

The underlying issue is that, as far as the wrapper is concerned, the number of arguments that come before start and end is not fixed. There are methods where there is 1 argument in front of them, there are methods where there are 2. Therefore the wrapper has to get to start and end via their keyword. A solution can be to always put start and end on locations 1 and 2. But that would mean that all methods need to be reformatted.

JrtPec commented 4 years ago

Marking this as "wontfix". start and end have to be named parameters for the reasons stated above.