You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So when you have a Series with the combination of a Float64Index and tuple values, getitem/[] gives an error:
In [46]: s = pd.Series([1,2,3], index=[0.0,0.1,0.2])
In [47]: s[0.0]
Out[47]: 1
In [48]: s = pd.Series([(1,1),(2,2),(3,3)], index=[0.0,0.1,0.2])
In [49]: s[0.0]
...
TypeError: len() of unsized object
When the values are not tuples, or when you have a regular index, or when using ix/loc/iloc this issue does not appear.
This issue is coming from geopandas (geopandas/geopandas#351), where a Series of Point geometries give the same error:
In [66]: import shapely.geometry
In [67]: s = pd.Series([(1,1),(2,2),(3,3)], index=[0.0,0.1,0.2])
In [68]: s = s.map(shapely.geometry.Point)
In [69]: s
Out[69]:
0.0 POINT (1 1)
0.1 POINT (2 2)
0.2 POINT (3 3)
dtype: object
In [70]: s[0.0]
...
TypeError: len() of unsized object
The text was updated successfully, but these errors were encountered:
I did a bit of digging and I think I found the issue. Float64Index.get_value tries to construct a Series with its result if the result is not scalar. A scalar cannot be given as the index for a new Series, so the construction of the series fails. This switch in particular seems problematic: https://github.com/pydata/pandas/blob/master/pandas/indexes/numeric.py#L303
I can't figure out what that switch is trying to do. Even if the resulting value is not a scalar, it seems to me like it should still be treated like any other value that would be retrieved from a Series and simply returned, not used to construct a new Series. Codecov reports that this switch is not tested: https://codecov.io/gh/pydata/pandas/src/8131b5151e10f1a5863ccadef739c21320830f54/pandas/indexes/numeric.py#L306 So it's difficult for me to figure out what the intended function of this code is.
I would propose to simply take out the switch and always return the retrieved value. Any objections?
So when you have a Series with the combination of a Float64Index and tuple values, getitem/
[]
gives an error:When the values are not tuples, or when you have a regular index, or when using
ix/loc/iloc
this issue does not appear.This issue is coming from geopandas (geopandas/geopandas#351), where a Series of Point geometries give the same error:
The text was updated successfully, but these errors were encountered: