iobis / pyobis

OBIS Python client
https://iobis.github.io/pyobis
MIT License
14 stars 10 forks source link

FutureWarning: explicitly cast to bool dtype #111

Closed bbest closed 1 year ago

bbest commented 1 year ago

When running this...

from pyobis.occurrences import OccQuery
occ = OccQuery()

o = occ.search(scientificname = "Mola mola")

I see this warning:

/opt/homebrew/lib/python3.10/site-packages/pyobis/occurrences/occurrences.py:167: FutureWarning:

In a future version, object-dtype columns with all-bool values will not be included in reductions with bool_only=True. Explicitly cast to bool dtype instead.
ayushanand18 commented 1 year ago

Thank you so much @bbest for highlighting this! It appears to be a warning thrown by pandas when we are concatenating new JSON data to already fetched data and all columns are by default set as object type.

I will try to resolve this by introducing a type-casting for all boolean value columns.

ayushanand18 commented 1 year ago

This issue is fixed in #113.

MathewBiddle commented 1 year ago

Looks like I'm getting this FutureWarning as well.

C:\Users\Mathew.Biddle\programs\Miniforge\envs\IOOS\Lib\site-packages\pyobis\occurrences\occurrences.py:167: FutureWarning: In a future version, object-dtype columns with all-bool values will not be included in reductions with bool_only=True. Explicitly cast to bool dtype instead.
  outdf = pd.concat([outdf, pd.DataFrame(res["results"])], ignore_index=True)
In[5]: pyobis.__version__
Out[5]: '1.2.6'
ayushanand18 commented 1 year ago

Thanks @MathewBiddle for reporting. It appears that the version you are using is the one published on PyPI. We fixed it in #113 and it is not currently published. We are working to resolve #116 and then push a new release.

ayushanand18 commented 1 year ago

With the new release v1.3.0 this issue seems to have resolved?

MathewBiddle commented 1 year ago

Looks like it's fixed now. Need to completely re-write my code with the new version though. I feel the jump from v1.2.6 to v1.3.0 breaks backward compatibility and should have been a major version change. See https://semver.org/.

ocefpaf commented 1 year ago

BTW, from a user perspective, warnings are not a big deal. With that said, for developers, specially Future/Deprecation warnings, should be something we pay attention to. @ayushanand18 the best way to keep track of those is to turn warnings into errors. See https://docs.pytest.org/en/7.1.x/how-to/capture-warnings.html#controlling-warnings.

ayushanand18 commented 1 year ago

Thank you @ocefpaf for the resource. Turning warnings into errors is the best thing, and I'll keep my dev environment updated to catch warnings while making changes.