Skip to content

Commit d58dba6

Browse files
committed
Implement getitem for iterables
1 parent 206f493 commit d58dba6

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

pandas/core/arrays/string_arrow.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pandas.core.dtypes.dtypes import register_extension_dtype
1111

1212
import pandas as pd
13-
from pandas.api.types import is_integer
13+
from pandas.api.types import is_array_like, is_bool_dtype, is_integer, is_integer_dtype
1414
from pandas.core.arrays.base import ExtensionArray
1515
from pandas.core.indexers import check_array_indexer
1616

@@ -241,20 +241,19 @@ def __getitem__(self, item):
241241
item = check_array_indexer(self, item)
242242

243243
if isinstance(item, Iterable):
244-
raise NotImplementedError("Iterable")
245-
# if not is_array_like(item):
246-
# item = np.array(item)
247-
# if is_integer_dtype(item) or (len(item) == 0):
248-
# return self.take(item)
249-
# elif is_bool_dtype(item):
250-
# indices = np.array(item)
251-
# indices = np.argwhere(indices).flatten()
252-
# return self.take(indices)
253-
# else:
254-
# raise IndexError(
255-
# """Only integers, slices and integer or
256-
# boolean arrays are valid indices."""
257-
# )
244+
if not is_array_like(item):
245+
item = np.array(item)
246+
if len(item) == 0:
247+
return type(self)(pa.chunked_array([], type=pa.string()))
248+
elif is_integer_dtype(item):
249+
return self.take(item)
250+
elif is_bool_dtype(item):
251+
return type(self)(self.data.filter(item))
252+
else:
253+
raise IndexError(
254+
"Only integers, slices and integer or "
255+
"boolean arrays are valid indices."
256+
)
258257
elif is_integer(item):
259258
if item < 0:
260259
item += len(self)

0 commit comments

Comments
 (0)