|
1 |
| -import textwrap |
2 | 1 | from typing import Tuple
|
3 |
| -import warnings |
4 | 2 |
|
5 | 3 | import numpy as np
|
6 | 4 |
|
|
10 | 8 | from pandas.util._decorators import Appender
|
11 | 9 |
|
12 | 10 | from pandas.core.dtypes.common import (
|
13 |
| - ensure_platform_int, |
14 | 11 | is_float,
|
15 | 12 | is_integer,
|
16 |
| - is_integer_dtype, |
17 | 13 | is_iterator,
|
18 | 14 | is_list_like,
|
19 | 15 | is_numeric_dtype,
|
|
34 | 30 | def get_indexers_list():
|
35 | 31 |
|
36 | 32 | return [
|
37 |
| - ("ix", _IXIndexer), |
38 | 33 | ("iloc", _iLocIndexer),
|
39 | 34 | ("loc", _LocIndexer),
|
40 | 35 | ("at", _AtIndexer),
|
@@ -112,9 +107,7 @@ def __call__(self, axis=None):
|
112 | 107 | new_self.axis = axis
|
113 | 108 | return new_self
|
114 | 109 |
|
115 |
| - def __iter__(self): |
116 |
| - raise NotImplementedError("ix is not iterable") |
117 |
| - |
| 110 | + # TODO: remove once geopandas no longer needs this |
118 | 111 | def __getitem__(self, key):
|
119 | 112 | # Used in ix and downstream in geopandas _CoordinateIndexer
|
120 | 113 | if type(key) is tuple:
|
@@ -921,9 +914,6 @@ def _getitem_lowerdim(self, tup: Tuple):
|
921 | 914 | if len(tup) > self.ndim:
|
922 | 915 | raise IndexingError("Too many indexers. handle elsewhere")
|
923 | 916 |
|
924 |
| - # to avoid wasted computation |
925 |
| - # df.ix[d1:d2, 0] -> columns first (True) |
926 |
| - # df.ix[0, ['C', 'B', A']] -> rows first (False) |
927 | 917 | for i, key in enumerate(tup):
|
928 | 918 | if is_label_like(key) or isinstance(key, tuple):
|
929 | 919 | section = self._getitem_axis(key, axis=i)
|
@@ -1004,6 +994,7 @@ def _getitem_nested_tuple(self, tup: Tuple):
|
1004 | 994 |
|
1005 | 995 | return obj
|
1006 | 996 |
|
| 997 | + # TODO: remove once geopandas no longer needs __getitem__ |
1007 | 998 | def _getitem_axis(self, key, axis: int):
|
1008 | 999 | if is_iterator(key):
|
1009 | 1000 | key = list(key)
|
@@ -1292,106 +1283,6 @@ def _get_slice_axis(self, slice_obj: slice, axis: int):
|
1292 | 1283 | return self._slice(indexer, axis=axis, kind="iloc")
|
1293 | 1284 |
|
1294 | 1285 |
|
1295 |
| -class _IXIndexer(_NDFrameIndexer): |
1296 |
| - """ |
1297 |
| - A primarily label-location based indexer, with integer position fallback. |
1298 |
| -
|
1299 |
| - Warning: Starting in 0.20.0, the .ix indexer is deprecated, in |
1300 |
| - favor of the more strict .iloc and .loc indexers. |
1301 |
| -
|
1302 |
| - ``.ix[]`` supports mixed integer and label based access. It is |
1303 |
| - primarily label based, but will fall back to integer positional |
1304 |
| - access unless the corresponding axis is of integer type. |
1305 |
| -
|
1306 |
| - ``.ix`` is the most general indexer and will support any of the |
1307 |
| - inputs in ``.loc`` and ``.iloc``. ``.ix`` also supports floating |
1308 |
| - point label schemes. ``.ix`` is exceptionally useful when dealing |
1309 |
| - with mixed positional and label based hierarchical indexes. |
1310 |
| -
|
1311 |
| - However, when an axis is integer based, ONLY label based access |
1312 |
| - and not positional access is supported. Thus, in such cases, it's |
1313 |
| - usually better to be explicit and use ``.iloc`` or ``.loc``. |
1314 |
| -
|
1315 |
| - See more at :ref:`Advanced Indexing <advanced>`. |
1316 |
| - """ |
1317 |
| - |
1318 |
| - _ix_deprecation_warning = textwrap.dedent( |
1319 |
| - """ |
1320 |
| - .ix is deprecated. Please use |
1321 |
| - .loc for label based indexing or |
1322 |
| - .iloc for positional indexing |
1323 |
| -
|
1324 |
| - See the documentation here: |
1325 |
| - http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#ix-indexer-is-deprecated""" # noqa: E501 |
1326 |
| - ) |
1327 |
| - |
1328 |
| - def __init__(self, name, obj): |
1329 |
| - warnings.warn(self._ix_deprecation_warning, FutureWarning, stacklevel=2) |
1330 |
| - super().__init__(name, obj) |
1331 |
| - |
1332 |
| - @Appender(_NDFrameIndexer._validate_key.__doc__) |
1333 |
| - def _validate_key(self, key, axis: int) -> bool: |
1334 |
| - """ |
1335 |
| - Returns |
1336 |
| - ------- |
1337 |
| - bool |
1338 |
| - """ |
1339 |
| - if isinstance(key, slice): |
1340 |
| - return True |
1341 |
| - |
1342 |
| - elif com.is_bool_indexer(key): |
1343 |
| - return True |
1344 |
| - |
1345 |
| - elif is_list_like_indexer(key): |
1346 |
| - return True |
1347 |
| - |
1348 |
| - else: |
1349 |
| - |
1350 |
| - self._convert_scalar_indexer(key, axis) |
1351 |
| - |
1352 |
| - return True |
1353 |
| - |
1354 |
| - def _convert_for_reindex(self, key, axis: int): |
1355 |
| - """ |
1356 |
| - Transform a list of keys into a new array ready to be used as axis of |
1357 |
| - the object we return (e.g. including NaNs). |
1358 |
| -
|
1359 |
| - Parameters |
1360 |
| - ---------- |
1361 |
| - key : list-like |
1362 |
| - Targeted labels. |
1363 |
| - axis: int |
1364 |
| - Where the indexing is being made. |
1365 |
| -
|
1366 |
| - Returns |
1367 |
| - ------- |
1368 |
| - list-like of labels. |
1369 |
| - """ |
1370 |
| - labels = self.obj._get_axis(axis) |
1371 |
| - |
1372 |
| - if com.is_bool_indexer(key): |
1373 |
| - key = check_bool_indexer(labels, key) |
1374 |
| - return labels[key] |
1375 |
| - |
1376 |
| - if isinstance(key, Index): |
1377 |
| - keyarr = labels._convert_index_indexer(key) |
1378 |
| - else: |
1379 |
| - # asarray can be unsafe, NumPy strings are weird |
1380 |
| - keyarr = com.asarray_tuplesafe(key) |
1381 |
| - |
1382 |
| - if is_integer_dtype(keyarr): |
1383 |
| - # Cast the indexer to uint64 if possible so |
1384 |
| - # that the values returned from indexing are |
1385 |
| - # also uint64. |
1386 |
| - keyarr = labels._convert_arr_indexer(keyarr) |
1387 |
| - |
1388 |
| - if not labels.is_integer(): |
1389 |
| - keyarr = ensure_platform_int(keyarr) |
1390 |
| - return labels.take(keyarr) |
1391 |
| - |
1392 |
| - return keyarr |
1393 |
| - |
1394 |
| - |
1395 | 1286 | class _LocationIndexer(_NDFrameIndexer):
|
1396 | 1287 | def __getitem__(self, key):
|
1397 | 1288 | if type(key) is tuple:
|
|
0 commit comments