Skip to content

Commit 670effe

Browse files
authored
Merge pull request #76 from pandas-dev/master
Sync Fork from Upstream Repo
2 parents b58db39 + d33b002 commit 670effe

File tree

12 files changed

+176
-233
lines changed

12 files changed

+176
-233
lines changed

pandas/core/algorithms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ def unique(values):
313313
314314
See Also
315315
--------
316-
Index.unique
317-
Series.unique
316+
Index.unique : Return unique values from an Index.
317+
Series.unique : Return unique values of Series object.
318318
319319
Examples
320320
--------
@@ -1515,7 +1515,7 @@ def take(arr, indices, axis: int = 0, allow_fill: bool = False, fill_value=None)
15151515
15161516
See Also
15171517
--------
1518-
numpy.take
1518+
numpy.take : Take elements from an array along an axis.
15191519
15201520
Examples
15211521
--------

pandas/core/frame.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ class DataFrame(NDFrame):
358358
--------
359359
DataFrame.from_records : Constructor from tuples, also record arrays.
360360
DataFrame.from_dict : From dicts of Series, arrays, or dicts.
361-
read_csv
362-
read_table
363-
read_clipboard
361+
read_csv : Read a comma-separated values (csv) file into DataFrame.
362+
read_table : Read general delimited file into DataFrame.
363+
read_clipboard : Read text from clipboard into DataFrame.
364364
365365
Examples
366366
--------
@@ -7393,8 +7393,9 @@ def corr(self, method="pearson", min_periods=1) -> "DataFrame":
73937393
73947394
See Also
73957395
--------
7396-
DataFrame.corrwith
7397-
Series.corr
7396+
DataFrame.corrwith : Compute pairwise correlation with another
7397+
DataFrame or Series.
7398+
Series.corr : Compute the correlation between two Series.
73987399
73997400
Examples
74007401
--------
@@ -7596,7 +7597,7 @@ def corrwith(self, other, axis=0, drop=False, method="pearson") -> Series:
75967597
75977598
See Also
75987599
--------
7599-
DataFrame.corr
7600+
DataFrame.corr : Compute pairwise correlation of columns.
76007601
"""
76017602
axis = self._get_axis_number(axis)
76027603
this = self._get_numeric_data()
@@ -8001,7 +8002,7 @@ def idxmin(self, axis=0, skipna=True) -> Series:
80018002
80028003
See Also
80038004
--------
8004-
Series.idxmin
8005+
Series.idxmin : Return index of the minimum element.
80058006
80068007
Notes
80078008
-----
@@ -8039,7 +8040,7 @@ def idxmax(self, axis=0, skipna=True) -> Series:
80398040
80408041
See Also
80418042
--------
8042-
Series.idxmax
8043+
Series.idxmax : Return index of the maximum element.
80438044
80448045
Notes
80458046
-----

pandas/core/indexes/base.py

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
is_categorical,
3333
is_categorical_dtype,
3434
is_datetime64_any_dtype,
35-
is_datetime64tz_dtype,
3635
is_dtype_equal,
3736
is_extension_array_dtype,
3837
is_float,
@@ -2525,14 +2524,8 @@ def _union(self, other, sort):
25252524
return other._get_reconciled_name_object(self)
25262525

25272526
# TODO(EA): setops-refactor, clean all this up
2528-
if is_datetime64tz_dtype(self):
2529-
lvals = self._ndarray_values
2530-
else:
2531-
lvals = self._values
2532-
if is_datetime64tz_dtype(other):
2533-
rvals = other._ndarray_values
2534-
else:
2535-
rvals = other._values
2527+
lvals = self._values
2528+
rvals = other._values
25362529

25372530
if sort is None and self.is_monotonic and other.is_monotonic:
25382531
try:
@@ -3078,48 +3071,6 @@ def _get_partial_string_timestamp_match_key(self, key):
30783071
# GH#10331
30793072
return key
30803073

3081-
def _convert_scalar_indexer(self, key, kind: str_t):
3082-
"""
3083-
Convert a scalar indexer.
3084-
3085-
Parameters
3086-
----------
3087-
key : label of the slice bound
3088-
kind : {'loc', 'getitem'}
3089-
"""
3090-
assert kind in ["loc", "getitem"]
3091-
3092-
if len(self) and not isinstance(self, ABCMultiIndex):
3093-
3094-
# we can raise here if we are definitive that this
3095-
# is positional indexing (eg. .loc on with a float)
3096-
# or label indexing if we are using a type able
3097-
# to be represented in the index
3098-
3099-
if kind == "getitem" and is_float(key):
3100-
if not self.is_floating():
3101-
raise KeyError(key)
3102-
3103-
elif kind == "loc" and is_float(key):
3104-
3105-
# we want to raise KeyError on string/mixed here
3106-
# technically we *could* raise a TypeError
3107-
# on anything but mixed though
3108-
if self.inferred_type not in [
3109-
"floating",
3110-
"mixed-integer-float",
3111-
"integer-na",
3112-
"string",
3113-
"mixed",
3114-
]:
3115-
raise KeyError(key)
3116-
3117-
elif kind == "loc" and is_integer(key):
3118-
if not (is_integer_dtype(self.dtype) or is_object_dtype(self.dtype)):
3119-
raise KeyError(key)
3120-
3121-
return key
3122-
31233074
def _validate_positional_slice(self, key: slice):
31243075
"""
31253076
For positional indexing, a slice must have either int or None

pandas/core/indexes/category.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,16 +574,6 @@ def get_indexer_non_unique(self, target):
574574
indexer, missing = self._engine.get_indexer_non_unique(codes)
575575
return ensure_platform_int(indexer), missing
576576

577-
@Appender(Index._convert_scalar_indexer.__doc__)
578-
def _convert_scalar_indexer(self, key, kind: str):
579-
assert kind in ["loc", "getitem"]
580-
if kind == "loc":
581-
try:
582-
return self.categories._convert_scalar_indexer(key, kind="loc")
583-
except TypeError:
584-
raise KeyError(key)
585-
return super()._convert_scalar_indexer(key, kind=kind)
586-
587577
@Appender(Index._convert_list_indexer.__doc__)
588578
def _convert_list_indexer(self, keyarr):
589579
# Return our indexer or raise if all of the values are not included in

pandas/core/indexes/datetimelike.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
is_bool_dtype,
1919
is_categorical_dtype,
2020
is_dtype_equal,
21-
is_float,
2221
is_integer,
2322
is_list_like,
2423
is_period_dtype,
@@ -377,32 +376,6 @@ def _format_attrs(self):
377376
# --------------------------------------------------------------------
378377
# Indexing Methods
379378

380-
def _convert_scalar_indexer(self, key, kind: str):
381-
"""
382-
We don't allow integer or float indexing on datetime-like when using
383-
loc.
384-
385-
Parameters
386-
----------
387-
key : label of the slice bound
388-
kind : {'loc', 'getitem'}
389-
"""
390-
assert kind in ["loc", "getitem"]
391-
392-
if not is_scalar(key):
393-
raise TypeError(key)
394-
395-
# we don't allow integer/float indexing for loc
396-
# we don't allow float indexing for getitem
397-
is_int = is_integer(key)
398-
is_flt = is_float(key)
399-
if kind == "loc" and (is_int or is_flt):
400-
raise KeyError(key)
401-
elif kind == "getitem" and is_flt:
402-
raise KeyError(key)
403-
404-
return super()._convert_scalar_indexer(key, kind=kind)
405-
406379
def _validate_partial_date_slice(self, reso: str):
407380
raise NotImplementedError
408381

pandas/core/indexes/interval.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,6 @@ def _should_fallback_to_positional(self):
514514
# positional in this case
515515
return self.dtype.subtype.kind in ["m", "M"]
516516

517-
@Appender(Index._convert_scalar_indexer.__doc__)
518-
def _convert_scalar_indexer(self, key, kind: str):
519-
assert kind in ["getitem", "loc"]
520-
# never iloc, so no-op
521-
return key
522-
523517
def _maybe_cast_slice_bound(self, label, side, kind):
524518
return getattr(self, side)._maybe_cast_slice_bound(label, side, kind)
525519

pandas/core/indexes/numeric.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,6 @@ def asi8(self) -> np.ndarray:
254254
# do not cache or you'll create a memory leak
255255
return self.values.view(self._default_dtype)
256256

257-
@Appender(Index._convert_scalar_indexer.__doc__)
258-
def _convert_scalar_indexer(self, key, kind: str):
259-
assert kind in ["loc", "getitem"]
260-
261-
# never iloc, which we don't coerce to integers
262-
key = self._maybe_cast_indexer(key)
263-
return super()._convert_scalar_indexer(key, kind=kind)
264-
265257

266258
class Int64Index(IntegerIndex):
267259
__doc__ = _num_index_shared_docs["class_descr"] % _int64_descr_args
@@ -391,12 +383,6 @@ def astype(self, dtype, copy=True):
391383
def _should_fallback_to_positional(self):
392384
return False
393385

394-
@Appender(Index._convert_scalar_indexer.__doc__)
395-
def _convert_scalar_indexer(self, key, kind: str):
396-
assert kind in ["loc", "getitem"]
397-
# no-op for non-iloc
398-
return key
399-
400386
@Appender(Index._convert_slice_indexer.__doc__)
401387
def _convert_slice_indexer(self, key: slice, kind: str):
402388
assert kind in ["loc", "getitem"]

pandas/core/indexing.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -866,16 +866,7 @@ def _validate_key(self, key, axis: int):
866866
# slice of labels (where start-end in labels)
867867
# slice of integers (only if in the labels)
868868
# boolean
869-
870-
if isinstance(key, slice):
871-
return
872-
873-
if com.is_bool_indexer(key):
874-
return
875-
876-
if not is_list_like_indexer(key):
877-
labels = self.obj._get_axis(axis)
878-
labels._convert_scalar_indexer(key, kind="loc")
869+
pass
879870

880871
def _has_valid_setitem_indexer(self, indexer) -> bool:
881872
return True
@@ -1139,15 +1130,6 @@ def _convert_to_indexer(self, key, axis: int, is_setter: bool = False):
11391130
if isinstance(key, slice):
11401131
return labels._convert_slice_indexer(key, kind="loc")
11411132

1142-
if is_scalar(key):
1143-
# try to find out correct indexer, if not type correct raise
1144-
try:
1145-
key = labels._convert_scalar_indexer(key, kind="loc")
1146-
except KeyError:
1147-
# but we will allow setting
1148-
if not is_setter:
1149-
raise
1150-
11511133
# see if we are positional in nature
11521134
is_int_index = labels.is_integer()
11531135
is_int_positional = is_integer(key) and not is_int_index
@@ -2029,11 +2011,17 @@ def _convert_key(self, key, is_setter: bool = False):
20292011
if is_setter:
20302012
return list(key)
20312013

2032-
lkey = list(key)
2033-
for n, (ax, i) in enumerate(zip(self.obj.axes, key)):
2034-
lkey[n] = ax._convert_scalar_indexer(i, kind="loc")
2014+
return key
20352015

2036-
return tuple(lkey)
2016+
def __getitem__(self, key):
2017+
if self.ndim != 1 or not is_scalar(key):
2018+
# FIXME: is_scalar check is a kludge
2019+
return super().__getitem__(key)
2020+
2021+
# Like Index.get_value, but we do not allow positional fallback
2022+
obj = self.obj
2023+
loc = obj.index.get_loc(key)
2024+
return obj.index._get_values_for_loc(obj, loc, key)
20372025

20382026

20392027
@Appender(IndexingMixin.iat.__doc__)

0 commit comments

Comments
 (0)