Skip to content

Commit 3f06416

Browse files
committed
Merge branch 'master' into ref-gbop
2 parents e5cf34d + ad5ee33 commit 3f06416

Some content is hidden

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

79 files changed

+1263
-645
lines changed

.pre-commit-config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
minimum_pre_commit_version: 2.9.2
22
exclude: ^LICENSES/|\.(html|csv|svg)$
3+
ci:
4+
autofix_prs: false
35
repos:
46
- repo: https://github.com/MarcoGorelli/absolufy-imports
57
rev: v0.3.0

.travis.yml

+2-9
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,9 @@ matrix:
3535
fast_finish: true
3636

3737
include:
38-
- arch: arm64
38+
- arch: arm64-graviton2
3939
env:
40-
- JOB="3.7, arm64" PYTEST_WORKERS=1 ENV_FILE="ci/deps/travis-37-arm64.yaml" PATTERN="(not slow and not network and not clipboard and not arm_slow)"
41-
42-
allow_failures:
43-
# Moved to allowed_failures 2020-09-29 due to timeouts https://github.com/pandas-dev/pandas/issues/36719
44-
- arch: arm64
45-
env:
46-
- JOB="3.7, arm64" PYTEST_WORKERS=1 ENV_FILE="ci/deps/travis-37-arm64.yaml" PATTERN="(not slow and not network and not clipboard and not arm_slow)"
47-
40+
- JOB="3.7, arm64" PYTEST_WORKERS="auto" ENV_FILE="ci/deps/travis-37-arm64.yaml" PATTERN="(not slow and not network and not clipboard and not arm_slow)"
4841

4942
before_install:
5043
- echo "before_install"

doc/_templates/sidebar-nav-bs.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
2+
<div class="bd-toc-item active">
3+
{% if pagename.startswith("reference") %}
4+
{{ generate_nav_html("sidebar", maxdepth=4, collapse=True, includehidden=True, titles_only=True) }}
5+
{% else %}
6+
{{ generate_nav_html("sidebar", maxdepth=4, collapse=False, includehidden=True, titles_only=True) }}
7+
{% endif %}
8+
</div>
9+
</nav>
7.14 KB
Loading
7.33 KB
Loading
7.59 KB
Loading
7.1 KB
Loading

doc/source/reference/style.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Styler properties
2323
:toctree: api/
2424

2525
Styler.env
26-
Styler.template
26+
Styler.template_html
2727
Styler.loader
2828

2929
Style application
@@ -53,6 +53,7 @@ Builtin styles
5353
Styler.highlight_null
5454
Styler.highlight_max
5555
Styler.highlight_min
56+
Styler.highlight_between
5657
Styler.background_gradient
5758
Styler.bar
5859

doc/source/user_guide/advanced.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ values across a level. For instance:
498498
)
499499
df = pd.DataFrame(np.random.randn(4, 2), index=midx)
500500
df
501-
df2 = df.mean(level=0)
501+
df2 = df.groupby(level=0).mean()
502502
df2
503503
df2.reindex(df.index, level=0)
504504

doc/source/user_guide/categorical.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ even if some categories are not present in the data:
633633
data=[[1, 2, 3], [4, 5, 6]],
634634
columns=pd.MultiIndex.from_arrays([["A", "B", "B"], columns]),
635635
)
636-
df.sum(axis=1, level=1)
636+
df.groupby(axis=1, level=1).sum()
637637
638638
Groupby will also show "unused" categories:
639639

doc/source/user_guide/groupby.rst

-8
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,6 @@ number:
320320
321321
s.groupby(level="second").sum()
322322
323-
The aggregation functions such as ``sum`` will take the level parameter
324-
directly. Additionally, the resulting index will be named according to the
325-
chosen level:
326-
327-
.. ipython:: python
328-
329-
s.sum(level="second")
330-
331323
Grouping with multiple levels is supported.
332324

333325
.. ipython:: python

doc/source/user_guide/style.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@
17101710
" Styler.loader, # the default\n",
17111711
" ])\n",
17121712
" )\n",
1713-
" template = env.get_template(\"myhtml.tpl\")"
1713+
" template_html = env.get_template(\"myhtml.tpl\")"
17141714
]
17151715
},
17161716
{

doc/source/whatsnew/v0.15.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Other enhancements:
154154
- ``Series.all`` and ``Series.any`` now support the ``level`` and ``skipna`` parameters (:issue:`8302`):
155155

156156
.. ipython:: python
157+
:okwarning:
157158
158159
s = pd.Series([False, True, False], index=[0, 0, 1])
159160
s.any(level=0)

doc/source/whatsnew/v1.3.0.rst

+18-8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ We provided some focused development on :class:`.Styler`, including altering met
117117
to accept more universal CSS language for arguments, such as ``'color:red;'`` instead of
118118
``[('color', 'red')]`` (:issue:`39564`). This is also added to the built-in methods
119119
to allow custom CSS highlighting instead of default background coloring (:issue:`40242`).
120+
Enhancements to other built-in methods include extending the :meth:`.Styler.background_gradient`
121+
method to shade elements based on a given gradient map and not be restricted only to
122+
values in the DataFrame (:issue:`39930` :issue:`22727` :issue:`28901`).
120123

121124
The :meth:`.Styler.apply` now consistently allows functions with ``ndarray`` output to
122125
allow more flexible development of UDFs when ``axis`` is ``None`` ``0`` or ``1`` (:issue:`39393`).
@@ -206,6 +209,7 @@ Other enhancements
206209
- :meth:`.Styler.background_gradient` now allows the ability to supply a specific gradient map (:issue:`22727`)
207210
- :meth:`.Styler.clear` now clears :attr:`Styler.hidden_index` and :attr:`Styler.hidden_columns` as well (:issue:`40484`)
208211
- Builtin highlighting methods in :class:`Styler` have a more consistent signature and css customisability (:issue:`40242`)
212+
- :meth:`.Styler.highlight_between` added to list of builtin styling methods (:issue:`39821`)
209213
- :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`)
210214
- :meth:`pandas.read_stata` and :class:`StataReader` support reading data from compressed files.
211215
- Add support for parsing ``ISO 8601``-like timestamps with negative signs to :meth:`pandas.Timedelta` (:issue:`37172`)
@@ -563,6 +567,7 @@ Deprecations
563567
- Deprecated allowing partial failure in :meth:`Series.transform` and :meth:`DataFrame.transform` when ``func`` is list-like or dict-like and raises anything but ``TypeError``; ``func`` raising anything but a ``TypeError`` will raise in a future version (:issue:`40211`)
564568
- Deprecated support for ``np.ma.mrecords.MaskedRecords`` in the :class:`DataFrame` constructor, pass ``{name: data[name] for name in data.dtype.names}`` instead (:issue:`40363`)
565569
- Deprecated the use of ``**kwargs`` in :class:`.ExcelWriter`; use the keyword argument ``engine_kwargs`` instead (:issue:`40430`)
570+
- Deprecated the ``level`` keyword for :class:`DataFrame` and :class:`Series` aggregations; use groupby instead (:issue:`39983`)
566571

567572
.. ---------------------------------------------------------------------------
568573
@@ -818,24 +823,29 @@ ExtensionArray
818823
- Fixed a bug where some properties of subclasses of :class:`PandasExtensionDtype` where improperly cached (:issue:`40329`)
819824
-
820825

826+
Styler
827+
^^^^^^
828+
829+
- Bug in :class:`Styler` where ``subset`` arg in methods raised an error for some valid multiindex slices (:issue:`33562`)
830+
- :class:`Styler` rendered HTML output minor alterations to support w3 good code standard (:issue:`39626`)
831+
- Bug in :class:`Styler` where rendered HTML was missing a column class identifier for certain header cells (:issue:`39716`)
832+
- Bug in :meth:`Styler.background_gradient` where text-color was not determined correctly (:issue:`39888`)
833+
- Bug in :class:`Styler` where multiple elements in CSS-selectors were not correctly added to ``table_styles`` (:issue:`39942`)
834+
- Bug in :class:`.Styler` where copying from Jupyter dropped top left cell and misaligned headers (:issue:`12147`)
835+
- Bug in :class:`.Styler.where` where ``kwargs`` were not passed to the applicable callable (:issue:`40845`)
836+
- Bug in :class:`Styler` which caused CSS to duplicate on multiple renders. (:issue:`39395`, :issue:`40334`)
837+
838+
821839
Other
822840
^^^^^
823841
- Bug in :class:`Index` constructor sometimes silently ignoring a specified ``dtype`` (:issue:`38879`)
824842
- Bug in :func:`pandas.api.types.infer_dtype` not recognizing Series, Index or array with a period dtype (:issue:`23553`)
825843
- Bug in :func:`pandas.api.types.infer_dtype` raising an error for general :class:`.ExtensionArray` objects. It will now return ``"unknown-array"`` instead of raising (:issue:`37367`)
826844
- Bug in constructing a :class:`Series` from a list and a :class:`PandasDtype` (:issue:`39357`)
827-
- Bug in :class:`Styler` which caused CSS to duplicate on multiple renders. (:issue:`39395`, :issue:`40334`)
828845
- ``inspect.getmembers(Series)`` no longer raises an ``AbstractMethodError`` (:issue:`38782`)
829846
- Bug in :meth:`Series.where` with numeric dtype and ``other = None`` not casting to ``nan`` (:issue:`39761`)
830847
- :meth:`Index.where` behavior now mirrors :meth:`Index.putmask` behavior, i.e. ``index.where(mask, other)`` matches ``index.putmask(~mask, other)`` (:issue:`39412`)
831848
- Bug in :func:`pandas.testing.assert_series_equal`, :func:`pandas.testing.assert_frame_equal`, :func:`pandas.testing.assert_index_equal` and :func:`pandas.testing.assert_extension_array_equal` incorrectly raising when an attribute has an unrecognized NA type (:issue:`39461`)
832-
- Bug in :class:`Styler` where ``subset`` arg in methods raised an error for some valid multiindex slices (:issue:`33562`)
833-
- :class:`Styler` rendered HTML output minor alterations to support w3 good code standard (:issue:`39626`)
834-
- Bug in :class:`Styler` where rendered HTML was missing a column class identifier for certain header cells (:issue:`39716`)
835-
- Bug in :meth:`Styler.background_gradient` where text-color was not determined correctly (:issue:`39888`)
836-
- Bug in :class:`Styler` where multiple elements in CSS-selectors were not correctly added to ``table_styles`` (:issue:`39942`)
837-
- Bug in :class:`.Styler` where copying from Jupyter dropped top left cell and misaligned headers (:issue:`12147`)
838-
- Bug in :class:`.Styler.where` where ``kwargs`` were not passed to the applicable callable (:issue:`40845`)
839849
- Bug in :meth:`DataFrame.equals`, :meth:`Series.equals`, :meth:`Index.equals` with object-dtype containing ``np.datetime64("NaT")`` or ``np.timedelta64("NaT")`` (:issue:`39650`)
840850
- Bug in :func:`pandas.util.show_versions` where console JSON output was not proper JSON (:issue:`39701`)
841851
- Bug in :meth:`DataFrame.convert_dtypes` incorrectly raised ValueError when called on an empty DataFrame (:issue:`40393`)

pandas/_config/config.py

+16-19
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
4949
"""
5050

51+
from __future__ import annotations
52+
5153
from collections import namedtuple
5254
from contextlib import (
5355
ContextDecorator,
@@ -57,12 +59,7 @@
5759
from typing import (
5860
Any,
5961
Callable,
60-
Dict,
6162
Iterable,
62-
List,
63-
Optional,
64-
Tuple,
65-
Type,
6663
cast,
6764
)
6865
import warnings
@@ -73,16 +70,16 @@
7370
RegisteredOption = namedtuple("RegisteredOption", "key defval doc validator cb")
7471

7572
# holds deprecated option metadata
76-
_deprecated_options: Dict[str, DeprecatedOption] = {}
73+
_deprecated_options: dict[str, DeprecatedOption] = {}
7774

7875
# holds registered option metadata
79-
_registered_options: Dict[str, RegisteredOption] = {}
76+
_registered_options: dict[str, RegisteredOption] = {}
8077

8178
# holds the current values for registered options
82-
_global_config: Dict[str, Any] = {}
79+
_global_config: dict[str, Any] = {}
8380

8481
# keys which have a special meaning
85-
_reserved_keys: List[str] = ["all"]
82+
_reserved_keys: list[str] = ["all"]
8683

8784

8885
class OptionError(AttributeError, KeyError):
@@ -194,7 +191,7 @@ def get_default_val(pat: str):
194191
class DictWrapper:
195192
""" provide attribute-style access to a nested dict"""
196193

197-
def __init__(self, d: Dict[str, Any], prefix: str = ""):
194+
def __init__(self, d: dict[str, Any], prefix: str = ""):
198195
object.__setattr__(self, "d", d)
199196
object.__setattr__(self, "prefix", prefix)
200197

@@ -428,8 +425,8 @@ def register_option(
428425
key: str,
429426
defval: object,
430427
doc: str = "",
431-
validator: Optional[Callable[[Any], Any]] = None,
432-
cb: Optional[Callable[[str], Any]] = None,
428+
validator: Callable[[Any], Any] | None = None,
429+
cb: Callable[[str], Any] | None = None,
433430
) -> None:
434431
"""
435432
Register an option in the package-wide pandas config object
@@ -500,7 +497,7 @@ def register_option(
500497

501498

502499
def deprecate_option(
503-
key: str, msg: Optional[str] = None, rkey: Optional[str] = None, removal_ver=None
500+
key: str, msg: str | None = None, rkey: str | None = None, removal_ver=None
504501
) -> None:
505502
"""
506503
Mark option `key` as deprecated, if code attempts to access this option,
@@ -547,7 +544,7 @@ def deprecate_option(
547544
# functions internal to the module
548545

549546

550-
def _select_options(pat: str) -> List[str]:
547+
def _select_options(pat: str) -> list[str]:
551548
"""
552549
returns a list of keys matching `pat`
553550
@@ -565,7 +562,7 @@ def _select_options(pat: str) -> List[str]:
565562
return [k for k in keys if re.search(pat, k, re.I)]
566563

567564

568-
def _get_root(key: str) -> Tuple[Dict[str, Any], str]:
565+
def _get_root(key: str) -> tuple[dict[str, Any], str]:
569566
path = key.split(".")
570567
cursor = _global_config
571568
for p in path[:-1]:
@@ -674,7 +671,7 @@ def pp_options_list(keys: Iterable[str], width=80, _print: bool = False):
674671
from itertools import groupby
675672
from textwrap import wrap
676673

677-
def pp(name: str, ks: Iterable[str]) -> List[str]:
674+
def pp(name: str, ks: Iterable[str]) -> list[str]:
678675
pfx = "- " + name + ".[" if name else ""
679676
ls = wrap(
680677
", ".join(ks),
@@ -687,7 +684,7 @@ def pp(name: str, ks: Iterable[str]) -> List[str]:
687684
ls[-1] = ls[-1] + "]"
688685
return ls
689686

690-
ls: List[str] = []
687+
ls: list[str] = []
691688
singles = [x for x in sorted(keys) if x.find(".") < 0]
692689
if singles:
693690
ls += pp("", singles)
@@ -760,7 +757,7 @@ def inner(key: str, *args, **kwds):
760757
# arg in register_option
761758

762759

763-
def is_type_factory(_type: Type[Any]) -> Callable[[Any], None]:
760+
def is_type_factory(_type: type[Any]) -> Callable[[Any], None]:
764761
"""
765762
766763
Parameters
@@ -826,7 +823,7 @@ def inner(x) -> None:
826823
return inner
827824

828825

829-
def is_nonnegative_int(value: Optional[int]) -> None:
826+
def is_nonnegative_int(value: int | None) -> None:
830827
"""
831828
Verify that value is None or a positive int.
832829

pandas/_config/display.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
Unopinionated display configuration.
33
"""
44

5+
from __future__ import annotations
6+
57
import locale
68
import sys
7-
from typing import Optional
89

910
from pandas._config import config as cf
1011

1112
# -----------------------------------------------------------------------------
1213
# Global formatting options
13-
_initial_defencoding: Optional[str] = None
14+
_initial_defencoding: str | None = None
1415

1516

1617
def detect_console_encoding() -> str:

pandas/_libs/index.pyx

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ cdef class IndexEngine:
7474
return val in self.mapping
7575

7676
cpdef get_loc(self, object val):
77+
# -> Py_ssize_t | slice | ndarray[bool]
7778
cdef:
7879
Py_ssize_t loc
7980

@@ -109,6 +110,7 @@ cdef class IndexEngine:
109110
raise KeyError(val)
110111

111112
cdef inline _get_loc_duplicates(self, object val):
113+
# -> Py_ssize_t | slice | ndarray[bool]
112114
cdef:
113115
Py_ssize_t diff
114116

@@ -142,6 +144,7 @@ cdef class IndexEngine:
142144
cdef _unpack_bool_indexer(self,
143145
ndarray[uint8_t, ndim=1, cast=True] indexer,
144146
object val):
147+
# Returns ndarray[bool] or int
145148
cdef:
146149
ndarray[intp_t, ndim=1] found
147150
int count

pandas/_libs/index_class_helper.pxi.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ cdef class {{name}}Engine(IndexEngine):
4444
raise KeyError(val)
4545
{{endif}}
4646

47-
cdef void _call_map_locations(self, ndarray values):
48-
self.mapping.map_locations(algos.ensure_{{name.lower()}}(values))
47+
cdef void _call_map_locations(self, ndarray[{{dtype}}_t] values):
48+
self.mapping.map_locations(values)
4949

5050
cdef _maybe_get_bool_indexer(self, object val):
5151
# Returns ndarray[bool] or int

0 commit comments

Comments
 (0)