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

date kwarg does not seem to work for get_dataframe() #71

Open
econstack opened this issue Feb 19, 2024 · 4 comments
Open

date kwarg does not seem to work for get_dataframe() #71

econstack opened this issue Feb 19, 2024 · 4 comments
Assignees
Milestone

Comments

@econstack
Copy link

Thank you for the update! After updating kwarg data_date to date for the get_dataframe() method, it does not seem to accept tuples as datetime objects or as strings. Both wbdata.get_dataframe({"NY.GDP.MKTP.CD": "value"}, date=["2000", "2022"]) and

start_year = datetime(2000, 1, 1)
end_year = datetime(2022, 1, 1)
df = wbdata.get_dataframe({"NY.GDP.MKTP.CD": "value"}, date=[start_year, end_year])

yield error TypeError: expected string or bytes-like object with additional error logging point to this line in the _parse_date method:

    if PATTERN_YEAR.fullmatch(date):
@econstack
Copy link
Author

Additional information. I reverted to version 0.3 and it seems that the the kwargs country and data_date also no longer works.

@OliverSherouse
Copy link
Owner

Thank you for the report, I can reproduce this behavior and will investigate further. I'm surprised that you had any trouble with version 0.3, since no changes were made to that version. As a workaround, you should be able to pull the whole series as a dataframe and slice down the the countries and years you're looking for.

@OliverSherouse OliverSherouse self-assigned this Feb 19, 2024
@OliverSherouse
Copy link
Owner

Bit of an update here. It seems that some of the problem was upstream, and has now been fixed. Unfortunately, wbdata isn't properly handling the dates as a list. But if you specify them as a tuple, your examples work:

In [20]: wbdata.get_dataframe({"NY.GDP.MKTP.CD": "value"}, date=("2000", "2022"))
Out[20]: 
                                         value
country                     date              
Africa Eastern and Southern 2022  1.185138e+12
                            2021  1.086531e+12
                            2020  9.288802e+11
                            2019  1.006191e+12
                            2018  1.012521e+12
...                                        ...
Zimbabwe                    2004  5.805598e+09
                            2003  5.727592e+09
                            2002  6.342116e+09
                            2001  6.777385e+09
                            2000  6.689958e+09

[6118 rows x 1 columns]

So that is your new workaround until I can fix this.

@OliverSherouse OliverSherouse added this to the 1.0.1 milestone Feb 23, 2024
@OliverSherouse
Copy link
Owner

I realized in looking at this that it isn't exactly a bug: that parameter is supposed to only take either a string, datetime, or 2-tuple of either. But it would probably be friendly to allow for lists since I doubt you're the only person who has tried this.

OliverSherouse added a commit that referenced this issue Mar 7, 2024
Allow sequences of length 2 for dates even though it should *really* be
a tuple.

Contributes to #71.

Signed-off-by: Oliver Sherouse <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants