0

Does the pandas.Series.isin function require the data to be hashable? I did not find this requirement in the documentation (Series.isin or Series, though I see the index needs to be hashable, not the data).

foo = ['x', 'y']
bar = pd.Series(foo, index=['a', 'b'])
baz = pd.Series([foo[0]], index=['c'])
print(bar.isin(baz))

works as expected and returns

a     True
b    False
dtype: bool

However, the following fails with the error TypeError: unhashable type: 'list':

foo = [['x', 'y'], ['z', 't']]
bar = pd.Series(foo, index=['a', 'b'])
baz = pd.Series([foo[0]], index=['c'])
print(bar.isin(baz))

Is that intended? Is it documented somewhere? Or is it a bug in pandas?

Keldorn
  • 1,980
  • 15
  • 25
  • Yes this is intended, list type object will make most of function in pandas do not work as expected – BENY Apr 15 '20 at 17:48
  • @YOBEN_S Is it documented? How about other (non list-type) non hashable objects? – Keldorn Apr 15 '20 at 18:08
  • You can convert to tuple – BENY Apr 15 '20 at 18:51
  • @YOBEN_S The example in the question is a basic version of [this question](https://stackoverflow.com/questions/61230262/how-is-this-different-behaviour-possible-typeerror-unhashable-type-point/61235373#61235373) stressing the root of the issue. In that case, the user has no control over the key (of type `shapely.geometry.point.Point`, used by geopandas). I would have naively expected that the existence of a `__eq__` operator was sufficient for `isin` to work. Where can I see that this is intended and not a bug? – Keldorn Apr 21 '20 at 12:26

0 Answers0