philsv / myeia

Python wrapper for the U.S. Energy Information Administration (EIA) API v2

Home Page:https://pypi.org/project/myeia/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request - multiple series and start-time

romanme2 opened this issue · comments

commented

Hi,

Thanks Phil for this great package. I was wondering if there was a way to have multiple series from the same route, and as an added bonus specify where the start time should begin. Right now I am using pd.merge_asof to merge columns together, but it would be extremely helpful to have it all done in one pull. Let me know if its possible with your package.

commented

Hi romanme,

thanks for the suggestion. I will think of a implemention for that. Maybe neext week I have some time for that. A bit busy right now. If you have a solution already feel free to PR and I will have a look.

commented

Please have a look at version 0.3.0 I added your requested changes:
97b8a1f

Is this it what you where looking for?

commented

I am having an issue with the code"start_date: str | none" TypeError: unsupported operand types for |: 'type' and 'NoneType'

commented

Sorry about that. Seems you are using python below 3.10, I got rid of the PEP604 union types. Should work in 0.3.1 now.

commented

Still getting this issue that is forcing me to restart the kernal. Thank you so much for implementing this feature!

Input In [17], in <cell line: 1>()
----> 1 from myeia.api import API

File ~/.local/lib/python3.8/site-packages/myeia/api.py:48, in
41 df.index = pd.to_datetime(df.index)
42 return df
45 def get_date_range(
46 start_date: Union[str, None] = None,
47 end_date: Union[str, None] = None,
---> 48 ) -> tuple[str, str]:
49 """
50 Helper function to get the start and end date for a given series.
51 """
52 if not start_date:

commented

Sorry for that rough update. Types issues should be fixed now in 0.3.2

commented

One more thing, I am getting this error. Any idea?

UnboundLocalError Traceback (most recent call last)
Input In [68], in <cell line: 6>()
2 import matplotlib.pyplot as plt
3 import myeia
----> 6 eia.get_series_via_route(
7 route="/petroleum/crd/crpdn",
8 series=["MCRFPP51",'MCRFPP51'],
9 frequency="monthly",
10 facet='product',
11 start_date="2021-01-01"
12 ,end_date="2021-01-31"
13 )

File ~/.local/lib/python3.8/site-packages/myeia/api.py:169, in API.get_series_via_route(self, route, series, frequency, facet, new_name, start_date, end_date)
166 elif facet == "seriesId":
167 df = base_df[["period", "value", "seriesDescription", "seriesId"]]
--> 169 df.reset_index(drop=True, inplace=True)
170 name = new_name if new_name != "" else df[df.columns[2]][0]
171 df.rename(columns={df.columns[1]: name}, inplace=True)

UnboundLocalError: local variable 'df' referenced before assignment

Your trying to get monthly data within a month? That does not make sense.

Try e.g.
facet='series',
start_date="2021-01-01"
end_date="2021-02-31"

and it should work, otherwise you will just get an empty dataframe back, as there are no data.

Works great! Thank you for this wonderful python package!.