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
Interpolate_to_grid - Unexpected behavior when using Pandas dataframe #1029
Comments
I had @dtho143 post this so we could see if @dopplershift et al. want to handle this conversion/check or if we are still only going to accept "array_like". The docs clearly mention accepting only "array_like", but the odd behavior of this working for some interpolations and not others could cause some confusion. I do like either of @ahuang11 's solutions, but does the former open a can of worms (checking for xr.Dataset, xr.DataArray, etc.)? |
I'd be interested in seeing a way to handle this as well (and would be willing to work on it), but I'm not sure if always forcing it directly to NumPy arrays is the best approach, given the plans to move to an xarray-centric model in the near future. However, adding the special case for DataFrames/Series may be the best solution in the interim until the xarray-based refactoring could be done? |
@dtho143 Thanks for the excellent report, and sorry for not getting back to you sooner. It's been 🔥 🔥 🚒 around here. Yuck. So:
Maybe instead of checking for the type, we could get away with checking for if hasattr(x, 'values'):
x = x.values It still makes my skin crawl a bit, but the ugliness would be hidden until we could do better. I do wonder in the case of I should also add that since xarray is now a required dependency, we can add a dependency on pandas essentially for free. |
I was recently working with the
interpolate_to_grid
function, following the example from https://unidata.github.io/MetPy/latest/examples/gridding/Point_Interpolation.html, and I was encountering some unexpected behavior. In my case, I was looking at stations in a particular state instead of the entire country, and I had loaded my data from a csv into a Pandas dataframe. When I started interpolating my data, several interpolation methods (linear, cubic, rbf, Cressman, Barnes) worked fine, but when I tried working with natural neighbor and nearest neighbor, it would not work. When I changed the input x and y coordinates fromdf.Long
anddf.Lat
todf.Long.values
anddf.Lat.values
, the interpolation worked. The other interpolation methods I tried do not have a problem with usingdf.Long
anddf.Lat
, only the natural and nearest neighbor methods had an issue.hres
was too small, or it would generate one solid color cell that covered all of my stations. If my resolution was too large, it would not have any output at all.Code example (works)
Code example (does not work)
Error Message
Code example (works)
Code example (does not work)
Error Message
Technical Details:
Windows 7 Enterprise
Metpy version 0.10.0
Anaconda version 4.5.12
Python 3.7.1
The text was updated successfully, but these errors were encountered: