Skip to content

Commit ee495e5

Browse files
Merge remote-tracking branch 'upstream/master' into am-concat
2 parents ebad8a4 + 2ce801c commit ee495e5

Some content is hidden

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

68 files changed

+1056
-797
lines changed

.pre-commit-config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ repos:
127127
types: [python]
128128
files: ^pandas/tests/
129129
exclude: ^pandas/tests/extension/
130+
- id: unwanted-patters-pytest-xfail
131+
name: Check for use of pytest.xfail
132+
entry: pytest\.xfail
133+
language: pygrep
134+
types: [python]
135+
files: ^pandas/tests/
130136
- id: inconsistent-namespace-usage
131137
name: 'Check for inconsistent use of pandas namespace in tests'
132138
entry: python scripts/check_for_inconsistent_pandas_namespace.py

asv_bench/benchmarks/categoricals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def time_get_loc(self):
323323
self.index.get_loc(self.category)
324324

325325
def time_shallow_copy(self):
326-
self.index._shallow_copy()
326+
self.index._view()
327327

328328
def time_align(self):
329329
pd.DataFrame({"a": self.series, "b": self.series[:500]})

asv_bench/benchmarks/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def time_get_loc(self):
8686
self.index.get_loc(self.period)
8787

8888
def time_shallow_copy(self):
89-
self.index._shallow_copy()
89+
self.index._view()
9090

9191
def time_series_loc(self):
9292
self.series.loc[self.period]

asv_bench/benchmarks/rolling.py

+13
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,19 @@ def time_rolling_multiindex_creation(self):
255255

256256
class GroupbyEWM:
257257

258+
params = ["var", "std", "cov", "corr"]
259+
param_names = ["method"]
260+
261+
def setup(self, method):
262+
df = pd.DataFrame({"A": range(50), "B": range(50)})
263+
self.gb_ewm = df.groupby("A").ewm(com=1.0)
264+
265+
def time_groupby_method(self, method):
266+
getattr(self.gb_ewm, method)()
267+
268+
269+
class GroupbyEWMEngine:
270+
258271
params = ["cython", "numba"]
259272
param_names = ["engine"]
260273

asv_bench/benchmarks/timedelta.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def time_get_loc(self):
7474
self.index.get_loc(self.timedelta)
7575

7676
def time_shallow_copy(self):
77-
self.index._shallow_copy()
77+
self.index._view()
7878

7979
def time_series_loc(self):
8080
self.series.loc[self.timedelta]

doc/source/development/code_style.rst

+40
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,46 @@ For example:
161161
# wrong
162162
from common import test_base
163163

164+
Testing
165+
=======
166+
167+
Failing tests
168+
--------------
169+
170+
See https://docs.pytest.org/en/latest/skipping.html for background.
171+
172+
Do not use ``pytest.xfail``
173+
---------------------------
174+
175+
Do not use this method. It has the same behavior as ``pytest.skip``, namely
176+
it immediately stops the test and does not check if the test will fail. If
177+
this is the behavior you desire, use ``pytest.skip`` instead.
178+
179+
Using ``pytest.mark.xfail``
180+
---------------------------
181+
182+
Use this method if a test is known to fail but the manner in which it fails
183+
is not meant to be captured. It is common to use this method for a test that
184+
exhibits buggy behavior or a non-implemented feature. If
185+
the failing test has flaky behavior, use the argument ``strict=False``. This
186+
will make it so pytest does not fail if the test happens to pass.
187+
188+
Prefer the decorator ``@pytest.mark.xfail`` and the argument ``pytest.param``
189+
over usage within a test so that the test is appropriately marked during the
190+
collection phase of pytest. For xfailing a test that involves multiple
191+
parameters, a fixture, or a combination of these, it is only possible to
192+
xfail during the testing phase. To do so, use the ``request`` fixture:
193+
194+
.. code-block:: python
195+
196+
import pytest
197+
198+
def test_xfail(request):
199+
request.node.add_marker(pytest.mark.xfail(reason="Indicate why here"))
200+
201+
xfail is not to be used for tests involving failure due to invalid user arguments.
202+
For these tests, we need to verify the correct exception type and error message
203+
is being raised, using ``pytest.raises`` instead.
164204

165205
Miscellaneous
166206
=============

doc/source/user_guide/dsintro.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ However, operations such as slicing will also slice the index.
126126
.. note::
127127

128128
We will address array-based indexing like ``s[[4, 3, 1]]``
129-
in :ref:`section <indexing>`.
129+
in :ref:`section on indexing <indexing>`.
130130

131131
Like a NumPy array, a pandas Series has a :attr:`~Series.dtype`.
132132

doc/source/user_guide/style.ipynb

+26-50
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@
140140
"metadata": {},
141141
"outputs": [],
142142
"source": [
143-
"s = df.style.set_table_attributes('class=\"table-cls\"')\n",
144-
"cls = pd.DataFrame(data=[['cls1', None], ['cls3', 'cls2 cls3']], index=[0,2], columns=['A', 'C'])\n",
145-
"s.set_td_classes(cls)"
143+
"css_classes = pd.DataFrame(data=[['cls1', None], ['cls3', 'cls2 cls3']], index=[0,2], columns=['A', 'C'])\n",
144+
"df.style.\\\n",
145+
" set_table_attributes('class=\"table-cls\"').\\\n",
146+
" set_td_classes(css_classes)"
146147
]
147148
},
148149
{
@@ -314,13 +315,10 @@
314315
"outputs": [],
315316
"source": [
316317
"def color_negative_red(val):\n",
317-
" \"\"\"\n",
318-
" Takes a scalar and returns a string with\n",
319-
" the css property `'color: red'` for negative\n",
320-
" strings, black otherwise.\n",
321-
" \"\"\"\n",
322-
" color = 'red' if val < 0 else 'black'\n",
323-
" return 'color: %s' % color"
318+
" \"\"\"Color negative scalars red.\"\"\"\n",
319+
" css = 'color: red;'\n",
320+
" if val < 0: return css\n",
321+
" return None"
324322
]
325323
},
326324
{
@@ -368,11 +366,9 @@
368366
"outputs": [],
369367
"source": [
370368
"def highlight_max(s):\n",
371-
" '''\n",
372-
" highlight the maximum in a Series yellow.\n",
373-
" '''\n",
374-
" is_max = s == s.max()\n",
375-
" return ['background-color: yellow' if v else '' for v in is_max]"
369+
" \"\"\"Highlight the maximum in a Series bold-orange.\"\"\"\n",
370+
" css = 'background-color: orange; font-weight: bold;'\n",
371+
" return np.where(s == np.nanmax(s.values), css, None)"
376372
]
377373
},
378374
{
@@ -384,11 +380,20 @@
384380
"df.style.apply(highlight_max)"
385381
]
386382
},
383+
{
384+
"cell_type": "code",
385+
"execution_count": null,
386+
"metadata": {},
387+
"outputs": [],
388+
"source": [
389+
"df.style.apply(highlight_max, axis=1)"
390+
]
391+
},
387392
{
388393
"cell_type": "markdown",
389394
"metadata": {},
390395
"source": [
391-
"In this case the input is a `Series`, one column at a time.\n",
396+
"In this case the input is a `Series`, one column (or row) at a time.\n",
392397
"Notice that the output shape of `highlight_max` matches the input shape, an array with `len(s)` items."
393398
]
394399
},
@@ -406,8 +411,8 @@
406411
"outputs": [],
407412
"source": [
408413
"def compare_col(s, comparator=None):\n",
409-
" attr = 'background-color: #00BFFF;'\n",
410-
" return np.where(s < comparator, attr, '')"
414+
" css = 'background-color: #00BFFF;'\n",
415+
" return np.where(s < comparator, css, None)"
411416
]
412417
},
413418
{
@@ -442,41 +447,12 @@
442447
"cell_type": "markdown",
443448
"metadata": {},
444449
"source": [
445-
"Above we used `Styler.apply` to pass in each column one at a time.\n",
450+
"Above we used `Styler.apply` to pass in each column (or row) one at a time.\n",
446451
"\n",
447452
"<span style=\"background-color: #DEDEBE\">*Debugging Tip*: If you're having trouble writing your style function, try just passing it into <code style=\"background-color: #DEDEBE\">DataFrame.apply</code>. Internally, <code style=\"background-color: #DEDEBE\">Styler.apply</code> uses <code style=\"background-color: #DEDEBE\">DataFrame.apply</code> so the result should be the same.</span>\n",
448453
"\n",
449454
"What if you wanted to highlight just the maximum value in the entire table?\n",
450-
"Use `.apply(function, axis=None)` to indicate that your function wants the entire table, not one column or row at a time. Let's try that next.\n",
451-
"\n",
452-
"We'll rewrite our `highlight-max` to handle either Series (from `.apply(axis=0 or 1)`) or DataFrames (from `.apply(axis=None)`). We'll also allow the color to be adjustable, to demonstrate that `.apply`, and `.applymap` pass along keyword arguments."
453-
]
454-
},
455-
{
456-
"cell_type": "code",
457-
"execution_count": null,
458-
"metadata": {},
459-
"outputs": [],
460-
"source": [
461-
"def highlight_max(data, color='yellow'):\n",
462-
" '''\n",
463-
" highlight the maximum in a Series or DataFrame\n",
464-
" '''\n",
465-
" attr = 'background-color: {}'.format(color)\n",
466-
" if data.ndim == 1: # Series from .apply(axis=0) or axis=1\n",
467-
" is_max = data == data.max()\n",
468-
" return [attr if v else '' for v in is_max]\n",
469-
" else: # from .apply(axis=None)\n",
470-
" is_max = data == data.max().max()\n",
471-
" return pd.DataFrame(np.where(is_max, attr, ''),\n",
472-
" index=data.index, columns=data.columns)"
473-
]
474-
},
475-
{
476-
"cell_type": "markdown",
477-
"metadata": {},
478-
"source": [
479-
"When using ``Styler.apply(func, axis=None)``, the function must return a DataFrame with the same index and column labels."
455+
"Use `.apply(function, axis=None)` to indicate that your function wants the entire table, not one column or row at a time. In this case the return must be a DataFrame or ndarray of the same shape as the input. Let's try that next. "
480456
]
481457
},
482458
{
@@ -485,7 +461,7 @@
485461
"metadata": {},
486462
"outputs": [],
487463
"source": [
488-
"s = df.style.apply(highlight_max, color='darkorange', axis=None)\n",
464+
"s = df.style.apply(highlight_max, axis=None)\n",
489465
"s"
490466
]
491467
},

doc/source/whatsnew/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Version 1.2
2424
.. toctree::
2525
:maxdepth: 2
2626

27+
v1.2.3
2728
v1.2.2
2829
v1.2.1
2930
v1.2.0

doc/source/whatsnew/v1.2.2.rst

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. _whatsnew_122:
22

3-
What's new in 1.2.2 (February ??, 2021)
3+
What's new in 1.2.2 (February 09, 2021)
44
---------------------------------------
55

66
These are the changes in pandas 1.2.2. See :ref:`release` for a full changelog
@@ -21,11 +21,12 @@ Fixed regressions
2121
- Fixed regression in :meth:`~DataFrame.to_pickle` failing to create bz2/xz compressed pickle files with ``protocol=5`` (:issue:`39002`)
2222
- Fixed regression in :func:`pandas.testing.assert_series_equal` and :func:`pandas.testing.assert_frame_equal` always raising ``AssertionError`` when comparing extension dtypes (:issue:`39410`)
2323
- Fixed regression in :meth:`~DataFrame.to_csv` opening ``codecs.StreamWriter`` in binary mode instead of in text mode and ignoring user-provided ``mode`` (:issue:`39247`)
24+
- Fixed regression in :meth:`Categorical.astype` casting to incorrect dtype when ``np.int32`` is passed to dtype argument (:issue:`39402`)
2425
- Fixed regression in :meth:`~DataFrame.to_excel` creating corrupt files when appending (``mode="a"``) to an existing file (:issue:`39576`)
2526
- Fixed regression in :meth:`DataFrame.transform` failing in case of an empty DataFrame or Series (:issue:`39636`)
26-
- Fixed regression in :meth:`core.window.rolling.Rolling.count` where the ``min_periods`` argument would be set to ``0`` after the operation (:issue:`39554`)
27+
- Fixed regression in :meth:`~DataFrame.groupby` or :meth:`~DataFrame.resample` when aggregating an all-NaN or numeric object dtype column (:issue:`39329`)
28+
- Fixed regression in :meth:`.Rolling.count` where the ``min_periods`` argument would be set to ``0`` after the operation (:issue:`39554`)
2729
- Fixed regression in :func:`read_excel` that incorrectly raised when the argument ``io`` was a non-path and non-buffer and the ``engine`` argument was specified (:issue:`39528`)
28-
-
2930

3031
.. ---------------------------------------------------------------------------
3132
@@ -36,17 +37,7 @@ Bug fixes
3637

3738
- :func:`pandas.read_excel` error message when a specified ``sheetname`` does not exist is now uniform across engines (:issue:`39250`)
3839
- Fixed bug in :func:`pandas.read_excel` producing incorrect results when the engine ``openpyxl`` is used and the excel file is missing or has incorrect dimension information; the fix requires ``openpyxl`` >= 3.0.0, prior versions may still fail (:issue:`38956`, :issue:`39001`)
39-
-
40-
41-
.. ---------------------------------------------------------------------------
42-
43-
.. _whatsnew_122.other:
44-
45-
Other
46-
~~~~~
47-
48-
-
49-
-
40+
- Fixed bug in :func:`pandas.read_excel` sometimes producing a ``DataFrame`` with trailing rows of ``np.nan`` when the engine ``openpyxl`` is used (:issue:`39181`)
5041

5142
.. ---------------------------------------------------------------------------
5243
@@ -55,4 +46,4 @@ Other
5546
Contributors
5647
~~~~~~~~~~~~
5748

58-
.. contributors:: v1.2.1..v1.2.2|HEAD
49+
.. contributors:: v1.2.1..v1.2.2

doc/source/whatsnew/v1.2.3.rst

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.. _whatsnew_123:
2+
3+
What's new in 1.2.3 (March ??, 2021)
4+
------------------------------------
5+
6+
These are the changes in pandas 1.2.3. See :ref:`release` for a full changelog
7+
including other versions of pandas.
8+
9+
{{ header }}
10+
11+
.. ---------------------------------------------------------------------------
12+
13+
.. _whatsnew_123.regressions:
14+
15+
Fixed regressions
16+
~~~~~~~~~~~~~~~~~
17+
18+
-
19+
-
20+
21+
.. ---------------------------------------------------------------------------
22+
23+
.. _whatsnew_123.bug_fixes:
24+
25+
Bug fixes
26+
~~~~~~~~~
27+
28+
-
29+
-
30+
31+
.. ---------------------------------------------------------------------------
32+
33+
.. _whatsnew_123.other:
34+
35+
Other
36+
~~~~~
37+
38+
-
39+
-
40+
41+
.. ---------------------------------------------------------------------------
42+
43+
.. _whatsnew_123.contributors:
44+
45+
Contributors
46+
~~~~~~~~~~~~
47+
48+
.. contributors:: v1.2.2..v1.2.3|HEAD

doc/source/whatsnew/v1.3.0.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ Other enhancements
5353
- :meth:`DataFrame.apply` can now accept non-callable DataFrame properties as strings, e.g. ``df.apply("size")``, which was already the case for :meth:`Series.apply` (:issue:`39116`)
5454
- :meth:`Series.apply` can now accept list-like or dictionary-like arguments that aren't lists or dictionaries, e.g. ``ser.apply(np.array(["sum", "mean"]))``, which was already the case for :meth:`DataFrame.apply` (:issue:`39140`)
5555
- :meth:`DataFrame.plot.scatter` can now accept a categorical column as the argument to ``c`` (:issue:`12380`, :issue:`31357`)
56-
- :meth:`.Styler.set_tooltips` allows on hover tooltips to be added to styled HTML dataframes (:issue:`35643`)
56+
- :meth:`.Styler.set_tooltips` allows on hover tooltips to be added to styled HTML dataframes (:issue:`35643`, :issue:`21266`, :issue:`39317`)
5757
- :meth:`.Styler.set_tooltips_class` and :meth:`.Styler.set_table_styles` amended to optionally allow certain css-string input arguments (:issue:`39564`)
58+
- :meth:`.Styler.apply` now more consistently accepts ndarray function returns, i.e. in all cases for ``axis`` is ``0, 1 or None``. (:issue:`39359`)
5859
- :meth:`Series.loc.__getitem__` and :meth:`Series.loc.__setitem__` with :class:`MultiIndex` now raising helpful error message when indexer has too many dimensions (:issue:`35349`)
5960
- :meth:`pandas.read_stata` and :class:`StataReader` support reading data from compressed files.
6061

@@ -254,6 +255,7 @@ Performance improvements
254255
- Performance improvement in :meth:`core.window.rolling.Rolling.corr` and :meth:`core.window.rolling.Rolling.cov` (:issue:`39388`)
255256
- Performance improvement in :meth:`core.window.rolling.RollingGroupby.corr`, :meth:`core.window.expanding.ExpandingGroupby.corr`, :meth:`core.window.expanding.ExpandingGroupby.corr` and :meth:`core.window.expanding.ExpandingGroupby.cov` (:issue:`39591`)
256257
- Performance improvement in :func:`unique` for object data type (:issue:`37615`)
258+
- Performance improvement in :class:`core.window.rolling.ExpandingGroupby` aggregation methods (:issue:`39664`)
257259

258260
.. ---------------------------------------------------------------------------
259261

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,5 @@ dependencies:
113113
- tabulate>=0.8.3 # DataFrame.to_markdown
114114
- natsort # DataFrame.sort_values
115115
- pip:
116-
- git+https://github.com/pandas-dev/pydata-sphinx-theme.git@master
116+
- git+https://github.com/pandas-dev/pydata-sphinx-theme.git@2488b7defbd3d753dd5fcfc890fc4a7e79d25103
117117
- git+https://github.com/numpy/numpydoc

0 commit comments

Comments
 (0)