NOAA-OWP / hydrotools

Suite of tools for retrieving USGS NWIS observations and evaluating National Water Model (NWM) data.
Other
53 stars 12 forks source link

NWIS IV Client `FutureWarning` #209

Closed jarq6c closed 1 year ago

jarq6c commented 1 year ago

When using the nwis iv client, I receive this warning:

~/env/lib/python3.8/site-packages/hydrotools/nwis_client/iv.py:283: FutureWarning: In a future version, 
`df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To 
retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, 
`df.isetitem(i, newvals)` dfs.loc[:, "value"] = pd.to_numeric(dfs["value"], downcast="float")
aaraney commented 1 year ago

Thanks for opening and documenting this, @jarq6c. I should have some bandwidth late into the afternoon to look into this and also checkout the PR's that i've neglected for longer that I would like to admit.

aaraney commented 1 year ago

This looks like a pretty easy fix. We should just swap df.loc for setting with df[]. We need to set by replacement (copy) rather than in-place because are changing the data type of the underlying array when we downcast.

I'm glad to see that pandas is improving the consistency of it's copy vs view semantics.

aaraney commented 1 year ago

For record sake, the FutureWarning was adding in 1.5.0. You can find more details about it here.