tgherzog / wbgapi

Python module that makes using the World Bank's API a lot easier and more intuitive.
MIT License
140 stars 31 forks source link

Suppress FutureWarning also for labels #33

Closed laloune closed 9 months ago

laloune commented 10 months ago

the future warning was also triggered when using labels. This PR creates the columns directly after creating the frame, and set their types to str per default

(this is my very first PR of my life, sorry in advance if this is not relevant or silly)

tgherzog commented 10 months ago

@laloune can you provide steps to recreate this issue (before your fix) and tell me what python version you're running? Also confirm you have the latest wbgapi installed.

laloune commented 10 months ago

@tgherzog here you are: wbgapi: pip show wbgapi Name: wbgapi Version: 1.0.12

python: Python 3.12.0

Snippet to reproduces the issue:

import wbgapi as wb
data = wb.data.DataFrame("SP.POP.TOTL", time=range(2021,2022), economy='all',labels=True, skipAggs=True)
print(data)

it produces the warning: C:\Python\Lib\site-packages\wbgapi\data.py:353: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value 'Zimbabwe' has dtype incompatible with float64, please explicitly cast to a compatible dtype first. df2.loc[index_key, concepts[i]['value']] = row[i]['value']

laloune commented 9 months ago

Hello @tgherzog

any thoughts on this one ?

Cheers

laloune commented 9 months ago

any news about this PR ?

tgherzog commented 9 months ago

@laloune sorry for the delay, it's been busy here. Give me another week or so...

laloune commented 9 months ago

no problem :)

take care

tgherzog commented 9 months ago

@laloune sorry, I am not able to recreate the issue. What version of pandas are you running? Here's my test code: no error produced:

>>> import sys
>>> import pandas as pd
>>> import wbgapi as wb
>>> print(sys.version)
3.12.0 (v3.12.0:0fb18b02c8, Oct  2 2023, 09:45:56) [Clang 13.0.0 (clang-1300.0.29.30)]
>>> print(pd.__version__)
2.1.2
>>> print(wb.__version__)
1.0.12
>>> data = wb.data.DataFrame("SP.POP.TOTL", time=range(2021,2022), economy='all',labels=True, skipAggs=True)

No warning or error produced

This could possibility also be the consequence of an issue within the API which as since been resolved. Your issue looked specific to Zimbabwe and WBG might have fixed the issue.

laloune commented 9 months ago

@tgherzog upgrading pandas did the trick. I was still running 2.1.1

sorry for the inconvenience