8000 BUG-23224 Merge master and fix conflict · pandas-dev/pandas@9a2a053 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a2a053

Browse files
committed
BUG-23224 Merge master and fix conflict
2 parents 0590df8 + 145c227 commit 9a2a053

File tree

92 files changed

+3604
-1955
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+3604
-1955
lines changed

asv_bench/benchmarks/indexing.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
import numpy as np
44
import pandas.util.testing as tm
5-
from pandas import (Series, DataFrame, Panel, MultiIndex, Int64Index,
6-
Float64Index, IntervalIndex, CategoricalIndex,
5+
from pandas import (Series, DataFrame, Panel, MultiIndex,
6+
Int64Index, UInt64Index, Float64Index,
7+
IntervalIndex, CategoricalIndex,
78
IndexSlice, concat, date_range)
89

910

1011
class NumericSeriesIndexing(object):
1112

A851
1213
goal_time = 0.2
1314
params = [
14-
(Int64Index, Float64Index),
15+
(Int64Index, UInt64Index, Float64Index),
1516
('unique_monotonic_inc', 'nonunique_monotonic_inc'),
1617
]
1718
param_names = ['index_dtype', 'index_structure']
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import numpy as np
2+
3+
from pandas._libs.index import (Int64Engine, UInt64Engine, Float64Engine,
4+
ObjectEngine)
5+
6+
7+
class NumericEngineIndexing(object):
8+
9+
goal_time = 0.2
10+
params = [[Int64Engine, UInt64Engine, Float64Engine],
11+
[np.int64, np.uint64, np.float64],
12+
['monotonic_incr', 'monotonic_decr', 'non_monotonic'],
13+
]
14+
param_names = ['engine', 'dtype', 'index_type']
15+
16+
def setup(self, engine, dtype, index_type):
17+
N = 10**5
18+
values = list([1] * N + [2] * N + [3] * N)
19+
arr = {
20+
'monotonic_incr': np.array(values, dtype=dtype),
21+
'monotonic_decr': np.array(list(reversed(values)),
22+
dtype=dtype),
23+
'non_monotonic': np.array([1, 2, 3] * N, dtype=dtype),
24+
}[index_type]
25+
26+
self.data = engine(lambda: arr, len(arr))
27+
# code belows avoids populating the mapping etc. while timing.
28+
self.data.get_loc(2)
29+
30+
def time_get_loc(self, engine, dtype, index_type):
31+
self.data.get_loc(2)
32+
33+
34+
class ObjectEngineIndexing(object):
35+
36+
goal_time = 0.2
37+
params = [('monotonic_incr', 'monotonic_decr', 'non_monotonic')]
38+
param_names = ['index_type']
39+
40+
def setup(self, index_type):
41+
N = 10**5
42+
values = list('a' * N + 'b' * N + 'c' * N)
43+
arr = {
44+
'monotonic_incr': np.array(values, dtype=object),
45+
'monotonic_decr': np.array(list(reversed(values)), dtype=object),
46+
'non_monotonic': np.array(list('abc') * N, dtype=object),
47+
}[index_type]
48+
49+
self.data = ObjectEngine(lambda: arr, len(arr))
50+
# code belows avoids populating the mapping etc. while timing.
51+
self.data.get_loc('b')
52+
53+
def time_get_loc(self, index_type):
54+
self.data.get_loc('b')

ci/azure-windows-36.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ channels:
55
dependencies:
66
- blosc
77
- bottleneck
8+
- boost-cpp<1.67
89
- fastparquet
910
- feather-format
1011
- matplotlib
1112
- numexpr
1213
- numpy=1.14*
1314
- openpyxl=2.5.5
15+
- parquet-cpp
1416
- pyarrow
1517
- pytables
1618
- python-dateutil

ci/code_checks.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
echo "inside $0"
1818
[[ $LINT ]] || { echo "NOT Linting. To lint use: LINT=true $0 $1"; exit 0; }
19-
[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "doctests" ]] || { echo "Unkown command $1. Usage: $0 [lint|patterns|doctests]"; exit 9999; }
19+
[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "doctests" ]] || { echo "Unknown command $1. Usage: $0 [lint|patterns|doctests]"; exit 9999; }
2020

2121
source activate pandas
2222
RET=0
@@ -56,6 +56,11 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
5656
cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/ujson pandas/_libs/tslibs/src/datetime
5757
RET=$(($RET + $?)) ; echo $MSG "DONE"
5858

59+
# Imports - Check formatting using isort see setup.cfg for settings
60+
MSG='Check import format using isort ' ; echo $MSG
61+
isort --recursive --check-only pandas
62+
RET=$(($RET + $?)) ; echo $MSG "DONE"
63+
5964
fi
6065

6166
### PATTERNS ###
@@ -117,22 +122,22 @@ fi
117122
if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
118123

119124
MSG='Doctests frame.py' ; echo $MSG
120-
pytest --doctest-modules -v pandas/core/frame.py \
125+
pytest -q --doctest-modules pandas/core/frame.py \
121126
-k"-axes -combine -itertuples -join -nlargest -nsmallest -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack -to_stata"
122127
RET=$(($RET + $?)) ; echo $MSG "DONE"
123128

124129
MSG='Doctests series.py' ; echo $MSG
125-
pytest --doctest-modules -v pandas/core/series.py \
130+
pytest -q --doctest-modules pandas/core/series.py \
126131
-k"-nonzero -reindex -searchsorted -to_dict"
127132
RET=$(($RET + $?)) ; echo $MSG "DONE"
128133

129134
MSG='Doctests generic.py' ; echo $MSG
130-
pytest --doctest-modules -v pandas/core/generic.py \
135+
pytest -q --doctest-modules pandas/core/generic.py \
131136
-k"-_set_axis_name -_xs -describe -droplevel -groupby -interpolate -pct_change -pipe -reindex -reindex_axis -resample -to_json -transpose -values -xs"
132137
RET=$(($RET + $?)) ; echo $MSG "DONE"
133138

134139
MSG='Doctests top-level reshaping functions' ; echo $MSG
135-
pytest --doctest-modules -v \
140+
pytest -q --doctest-modules \
136141
pandas/core/reshape/concat.py \
137142
pandas/core/reshape/pivot.py \
138143
pandas/core/reshape/reshape.py \

ci/environment-dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies:
88
- flake8
99
- flake8-comprehensions
1010
- hypothesis>=3.58.0
11+
- isort
1112
- moto
1213
- pytest>=3.6
1314
- python-dateutil>=2.5.0

ci/requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ NumPy
55
flake8
66
flake8-comprehensions
77
hypothesis>=3.58.0
8+
isort
89
moto
910
pytest>=3.6
1011
python-dateutil>=2.5.0

ci/travis-36.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies:
1414
- geopandas
1515
- html5lib
1616
- ipython
17+
- isort
1718
- jinja2
1819
- lxml
1920
- matplotlib

doc/source/extending.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ There are two approaches for providing operator support for your ExtensionArray:
135135
2. Use an operator implementation from pandas that depends on operators that are already defined
136136
on the underlying elements (scalars) of the ExtensionArray.
137137

138+
.. note::
139+
140+
Regardless of the approach, you may want to set ``__array_priority__``
141+
if you want your implementation to be called when involved in binary operations
142+
with NumPy arrays.
143+
138144
For the first approach, you define selected operators, e.g., ``__add__``, ``__le__``, etc. that
139145
you want your ``ExtensionArray`` subclass to support.
140146

@@ -173,6 +179,16 @@ or not that succeeds depends on whether the operation returns a result
173179
that's valid for the ``ExtensionArray``. If an ``ExtensionArray`` cannot
174180
be reconstructed, an ndarray containing the scalars returned instead.
175181

182+
For ease of implementation and consistency with operations between pandas
183+
and NumPy ndarrays, we recommend *not* handling Series and Indexes in your binary ops.
184+
Instead, you should detect these cases and return ``NotImplemented``.
185+
When pandas encounters an operation like ``op(Series, ExtensionArray)``, pandas
186+
will
187+
188+
1. unbox the array from the ``Series`` (roughly ``Series.values``)
189+
2. call ``result = op(values, ExtensionArray)``
190+
3. re-box the result in a ``Series``
191+
176192
.. _extending.extension.testing:
177193

178194
Testing Extension Arrays

0 commit comments

Comments
 (0)
0