|
10 | 10 | from pandas.core.dtypes.dtypes import register_extension_dtype
|
11 | 11 |
|
12 | 12 | 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 |
14 | 14 | from pandas.core.arrays.base import ExtensionArray
|
15 | 15 | from pandas.core.indexers import check_array_indexer
|
16 | 16 |
|
@@ -241,20 +241,19 @@ def __getitem__(self, item):
|
241 | 241 | item = check_array_indexer(self, item)
|
242 | 242 |
|
243 | 243 | 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 | + ) |
258 | 257 | elif is_integer(item):
|
259 | 258 | if item < 0:
|
260 | 259 | item += len(self)
|
|
0 commit comments