Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0b51bd5

Browse files
committedNov 7, 2019
Merge remote-tracking branch 'upstream/master' into docfix-multiindex-set_levels
2 parents 11976fc + 08087d6 commit 0b51bd5

38 files changed

+634
-808
lines changed
 

‎ci/azure/posix.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@ jobs:
4545
PATTERN: "not slow and not network"
4646
LOCALE_OVERRIDE: "zh_CN.UTF-8"
4747

48-
py37_np_dev:
49-
ENV_FILE: ci/deps/azure-37-numpydev.yaml
50-
CONDA_PY: "37"
51-
PATTERN: "not slow and not network"
52-
TEST_ARGS: "-W error"
53-
PANDAS_TESTING_MODE: "deprecate"
54-
EXTRA_APT: "xsel"
48+
# https://github.com/pandas-dev/pandas/issues/29432
49+
# py37_np_dev:
50+
# ENV_FILE: ci/deps/azure-37-numpydev.yaml
51+
# CONDA_PY: "37"
52+
# PATTERN: "not slow and not network"
53+
# TEST_ARGS: "-W error"
54+
# PANDAS_TESTING_MODE: "deprecate"
55+
# EXTRA_APT: "xsel"
56+
# # TODO:
57+
# continueOnError: true
5558

5659
steps:
5760
- script: |

‎doc/source/getting_started/basics.rst

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -753,28 +753,51 @@ on an entire ``DataFrame`` or ``Series``, row- or column-wise, or elementwise.
753753
Tablewise function application
754754
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
755755

756-
``DataFrames`` and ``Series`` can of course just be passed into functions.
756+
``DataFrames`` and ``Series`` can be passed into functions.
757757
However, if the function needs to be called in a chain, consider using the :meth:`~DataFrame.pipe` method.
758-
Compare the following
759758

760-
.. code-block:: python
759+
First some setup:
760+
761+
.. ipython:: python
761762
762-
# f, g, and h are functions taking and returning ``DataFrames``
763-
>>> f(g(h(df), arg1=1), arg2=2, arg3=3)
763+
def extract_city_name(df):
764+
"""
765+
Chicago, IL -> Chicago for city_name column
766+
"""
767+
df['city_name'] = df['city_and_code'].str.split(",").str.get(0)
768+
return df
764769
765-
with the equivalent
770+
def add_country_name(df, country_name=None):
771+
"""
772+
Chicago -> Chicago-US for city_name column
773+
"""
774+
col = 'city_name'
775+
df['city_and_country'] = df[col] + country_name
776+
return df
766777
767-
.. code-block:: python
778+
df_p = pd.DataFrame({'city_and_code': ['Chicago, IL']})
779+
780+
781+
``extract_city_name`` and ``add_country_name`` are functions taking and returning ``DataFrames``.
782+
783+
Now compare the following:
784+
785+
.. ipython:: python
786+
787+
add_country_name(extract_city_name(df_p), country_name='US')
788+
789+
Is equivalent to:
790+
791+
.. ipython:: python
768792
769-
>>> (df.pipe(h)
770-
... .pipe(g, arg1=1)
771-
... .pipe(f, arg2=2, arg3=3))
793+
(df_p.pipe(extract_city_name)
794+
.pipe(add_country_name, country_name="US"))
772795
773796
Pandas encourages the second style, which is known as method chaining.
774797
``pipe`` makes it easy to use your own or another library's functions
775798
in method chains, alongside pandas' methods.
776799

777-
In the example above, the functions ``f``, ``g``, and ``h`` each expected the ``DataFrame`` as the first positional argument.
800+
In the example above, the functions ``extract_city_name`` and ``add_country_name`` each expected a ``DataFrame`` as the first positional argument.
778801
What if the function you wish to apply takes its data as, say, the second argument?
779802
In this case, provide ``pipe`` with a tuple of ``(callable, data_keyword)``.
780803
``.pipe`` will route the ``DataFrame`` to the argument specified in the tuple.

‎doc/source/user_guide/style.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"# Styling\n",
88
"\n",
9-
"This document is written as a Jupyter Notebook, and can be viewed or downloaded [here](http://nbviewer.ipython.org/github/pandas-dev/pandas/blob/master/doc/source/style.ipynb).\n",
9+
"This document is written as a Jupyter Notebook, and can be viewed or downloaded [here](http://nbviewer.ipython.org/github/pandas-dev/pandas/blob/master/doc/source/user_guide/style.ipynb).\n",
1010
"\n",
1111
"You can apply **conditional formatting**, the visual styling of a DataFrame\n",
1212
"depending on the data within, by using the ``DataFrame.style`` property.\n",

‎environment.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: pandas-dev
22
channels:
3-
- defaults
43
- conda-forge
54
dependencies:
65
# required
76
- numpy>=1.15
8-
- python=3
7+
- python=3.7
98
- python-dateutil>=2.6.1
109
- pytz
1110

@@ -22,7 +21,7 @@ dependencies:
2221
- flake8-comprehensions # used by flake8, linting of unnecessary comprehensions
2322
- flake8-rst>=0.6.0,<=0.7.0 # linting of code blocks in rst files
2423
- isort # check that imports are in the right order
25-
- mypy
24+
- mypy=0.720
2625
- pycodestyle # used by flake8
2726

2827
# documentation
@@ -54,7 +53,6 @@ dependencies:
5453
- moto # mock S3
5554
- pytest>=4.0.2
5655
- pytest-cov
57-
- pytest-mock
5856
- pytest-xdist
5957
- seaborn
6058
- statsmodels

‎pandas/_libs/algos.pyx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,77 @@ def rank_2d(rank_t[:, :] in_arr, axis=0, ties_method='average',
11501150
return ranks
11511151

11521152

1153+
ctypedef fused diff_t:
1154+
float64_t
1155+
float32_t
1156+
int8_t
1157+
int16_t
1158+
int32_t
1159+
int64_t
1160+
1161+
ctypedef fused out_t:
1162+
float32_t
1163+
float64_t
1164+
1165+
1166+
@cython.boundscheck(False)
1167+
@cython.wraparound(False)
1168+
def diff_2d(ndarray[diff_t, ndim=2] arr,
1169+
ndarray[out_t, ndim=2] out,
1170+
Py_ssize_t periods, int axis):
1171+
cdef:
1172+
Py_ssize_t i, j, sx, sy, start, stop
1173+
bint f_contig = arr.flags.f_contiguous
1174+
1175+
# Disable for unsupported dtype combinations,
1176+
# see https://github.com/cython/cython/issues/2646
1177+
if (out_t is float32_t
1178+
and not (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
1179+
raise NotImplementedError
1180+
elif (out_t is float64_t
1181+
and (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
1182+
raise NotImplementedError
1183+
else:
1184+
# We put this inside an indented else block to avoid cython build
1185+
# warnings about unreachable code
1186+
sx, sy = (<object>arr).shape
1187+
with nogil:
1188+
if f_contig:
1189+
if axis == 0:
1190+
if periods >= 0:
1191+
start, stop = periods, sx
1192+
else:
1193+
start, stop = 0, sx + periods
1194+
for j in range(sy):
1195+
for i in range(start, stop):
1196+
out[i, j] = arr[i, j] - arr[i - periods, j]
1197+
else:
1198+
if periods >= 0:
1199+
start, stop = periods, sy
1200+
else:
1201+
start, stop = 0, sy + periods
1202+
for j in range(start, stop):
1203+
for i in range(sx):
1204+
out[i, j] = arr[i, j] - arr[i, j - periods]
1205+
else:
1206+
if axis == 0:
1207+
if periods >= 0:
1208+
start, stop = periods, sx
1209+
else:
1210+
start, stop = 0, sx + periods
1211+
for i in range(start, stop):
1212+
for j in range(sy):
1213+
out[i, j] = arr[i, j] - arr[i - periods, j]
1214+
else:
1215+
if periods >= 0:
1216+
start, stop = periods, sy
1217+
else:
1218+
start, stop = 0, sy + periods
1219+
for i in range(sx):
1220+
for j in range(start, stop):
1221+
out[i, j] = arr[i, j] - arr[i, j - periods]
1222+
1223+
11531224
# generated from template
11541225
include "algos_common_helper.pxi"
11551226
include "algos_take_helper.pxi"

‎pandas/_libs/algos_common_helper.pxi.in

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,77 +4,6 @@ Template for each `dtype` helper function using 1-d template
44
WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
55
"""
66

7-
ctypedef fused diff_t:
8-
float64_t
9-
float32_t
10-
int8_t
11-
int16_t
12-
int32_t
13-
int64_t
14-
15-
ctypedef fused out_t:
16-
float32_t
17-
float64_t
18-
19-
20-
@cython.boundscheck(False)
21-
@cython.wraparound(False)
22-
def diff_2d(ndarray[diff_t, ndim=2] arr,
23-
ndarray[out_t, ndim=2] out,
24-
Py_ssize_t periods, int axis):
25-
cdef:
26-
Py_ssize_t i, j, sx, sy, start, stop
27-
bint f_contig = arr.flags.f_contiguous
28-
29-
# Disable for unsupported dtype combinations,
30-
# see https://github.com/cython/cython/issues/2646
31-
if (out_t is float32_t
32-
and not (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
33-
raise NotImplementedError
34-
elif (out_t is float64_t
35-
and (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
36-
raise NotImplementedError
37-
else:
38-
# We put this inside an indented else block to avoid cython build
39-
# warnings about unreachable code
40-
sx, sy = (<object>arr).shape
41-
with nogil:
42-
if f_contig:
43-
if axis == 0:
44-
if periods >= 0:
45-
start, stop = periods, sx
46-
else:
47-
start, stop = 0, sx + periods
48-
for j in range(sy):
49-
for i in range(start, stop):
50-
out[i, j] = arr[i, j] - arr[i - periods, j]
51-
else:
52-
if periods >= 0:
53-
start, stop = periods, sy
54-
else:
55-
start, stop = 0, sy + periods
56-
for j in range(start, stop):
57-
for i in range(sx):
58-
out[i, j] = arr[i, j] - arr[i, j - periods]
59-
else:
60-
if axis == 0:
61-
if periods >= 0:
62-
start, stop = periods, sx
63-
else:
64-
start, stop = 0, sx + periods
65-
for i in range(start, stop):
66-
for j in range(sy):
67-
out[i, j] = arr[i, j] - arr[i - periods, j]
68-
else:
69-
if periods >= 0:
70-
start, stop = periods, sy
71-
else:
72-
start, stop = 0, sy + periods
73-
for i in range(sx):
74-
for j in range(start, stop):
75-
out[i, j] = arr[i, j] - arr[i, j - periods]
76-
77-
787
# ----------------------------------------------------------------------
798
# ensure_dtype
809
# ----------------------------------------------------------------------

‎pandas/_libs/lib.pyx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def is_scalar(val: object) -> bool:
125125
- Interval
126126
- DateOffset
127127
- Fraction
128-
- Number
128+
- Number.
129129

130130
Returns
131131
-------
@@ -867,9 +867,10 @@ def is_list_like(obj: object, allow_sets: bool = True):
867867
868868
Parameters
869869
----------
870-
obj : The object to check
871-
allow_sets : boolean, default True
872-
If this parameter is False, sets will not be considered list-like
870+
obj : object
871+
The object to check.
872+
allow_sets : bool, default True
873+
If this parameter is False, sets will not be considered list-like.
873874
874875
.. versionadded:: 0.24.0
875876

‎pandas/_libs/missing.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ cpdef ndarray[uint8_t] isnaobj(ndarray arr):
121121

122122
@cython.wraparound(False)
123123
@cython.boundscheck(False)
124-
def isnaobj_old(ndarray arr):
124+
def isnaobj_old(arr: ndarray) -> ndarray:
125125
"""
126126
Return boolean mask denoting which elements of a 1-D array are na-like,
127127
defined as being any of:
@@ -156,7 +156,7 @@ def isnaobj_old(ndarray arr):
156156

157157
@cython.wraparound(False)
158158
@cython.boundscheck(False)
159-
def isnaobj2d(ndarray arr):
159+
def isnaobj2d(arr: ndarray) -> ndarray:
160160
"""
161161
Return boolean mask denoting which elements of a 2-D array are na-like,
162162
according to the criteria defined in `checknull`:
@@ -198,7 +198,7 @@ def isnaobj2d(ndarray arr):
198198

199199
@cython.wraparound(False)
200200
@cython.boundscheck(False)
201-
def isnaobj2d_old(ndarray arr):
201+
def isnaobj2d_old(arr: ndarray) -> ndarray:
202202
"""
203203
Return boolean mask denoting which elements of a 2-D array are na-like,
204204
according to the criteria defined in `checknull_old`:

‎pandas/_libs/window.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def _check_minp(win, minp, N, floor=None) -> int:
6969
if not util.is_integer_object(minp):
7070
raise ValueError("min_periods must be an integer")
7171
if minp > win:
72-
raise ValueError("min_periods (%d) must be <= "
73-
"window (%d)" % (minp, win))
72+
raise ValueError("min_periods (minp) must be <= "
73+
"window (win)".format(minp=minp, win=win))
7474
elif minp > N:
7575
minp = N + 1
7676
elif minp < 0:

‎pandas/core/arrays/interval.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ def _from_factorized(cls, values, original):
260260
Whether the intervals are closed on the left-side, right-side, both
261261
or neither.
262262
copy : bool, default False
263-
copy the data
263+
Copy the data.
264264
dtype : dtype or None, default None
265-
If None, dtype will be inferred
265+
If None, dtype will be inferred.
266266
267267
.. versionadded:: 0.23.0
268268
@@ -383,16 +383,16 @@ def from_arrays(cls, left, right, closed="right", copy=False, dtype=None):
383383
Parameters
384384
----------
385385
data : array-like (1-dimensional)
386-
Array of tuples
386+
Array of tuples.
387387
closed : {'left', 'right', 'both', 'neither'}, default 'right'
388388
Whether the intervals are closed on the left-side, right-side, both
389389
or neither.
390390
copy : bool, default False
391-
by-default copy the data, this is compat only and ignored
391+
By-default copy the data, this is compat only and ignored.
392392
dtype : dtype or None, default None
393-
If None, dtype will be inferred
393+
If None, dtype will be inferred.
394394
395-
..versionadded:: 0.23.0
395+
.. versionadded:: 0.23.0
396396
397397
Returns
398398
-------

0 commit comments

Comments
 (0)
Please sign in to comment.