Skip to content

Commit

Permalink
Merge branch 'master' into issue3566
Browse files Browse the repository at this point in the history
  • Loading branch information
leoluecken committed Jan 29, 2024
2 parents d915eba + b95d6d1 commit 56aced5
Show file tree
Hide file tree
Showing 39 changed files with 538 additions and 329 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
NB_KERNEL: python
MPLBACKEND: Agg
SEABORN_DATA: ${{ github.workspace }}/seaborn-data
PYDEVD_DISABLE_FILE_VALIDATION: 1

jobs:
build-docs:
Expand All @@ -24,7 +25,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup Python 3.11
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: "3.11"

Expand All @@ -35,7 +36,8 @@ jobs:
- name: Install pandoc
run: |
sudo apt-get install pandoc
wget https://github.com/jgm/pandoc/releases/download/3.1.11/pandoc-3.1.11-1-amd64.deb
sudo dpkg -i pandoc-3.1.11-1-amd64.deb
- name: Cache datasets
run: |
Expand Down Expand Up @@ -72,7 +74,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: ${{ matrix.python }}
allow-prereleases: true
Expand Down Expand Up @@ -101,7 +103,7 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup Python
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0

- name: Install tools
run: pip install mypy flake8
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012-2021, Michael L. Waskom
Copyright (c) 2012-2023, Michael L. Waskom
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ seaborn: statistical data visualization
=======================================

[![PyPI Version](https://img.shields.io/pypi/v/seaborn.svg)](https://pypi.org/project/seaborn/)
[![License](https://img.shields.io/pypi/l/seaborn.svg)](https://github.com/mwaskom/seaborn/blob/master/LICENSE)
[![License](https://img.shields.io/pypi/l/seaborn.svg)](https://github.com/mwaskom/seaborn/blob/master/LICENSE.md)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.03021/status.svg)](https://doi.org/10.21105/joss.03021)
[![Tests](https://github.com/mwaskom/seaborn/workflows/CI/badge.svg)](https://github.com/mwaskom/seaborn/actions)
[![Code Coverage](https://codecov.io/gh/mwaskom/seaborn/branch/master/graph/badge.svg)](https://codecov.io/gh/mwaskom/seaborn)
Expand Down
2 changes: 1 addition & 1 deletion doc/_docstrings/barplot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"id": "b53b65b8-5670-4905-aa39-36db04f4b813",
"metadata": {},
"source": [
"With long data, assign `x` and `y` to group by a categorical varaible and plot aggregated values, with confidence intervals:"
"With long data, assign `x` and `y` to group by a categorical variable and plot aggregated values, with confidence intervals:"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/_docstrings/histplot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Step functions, esepcially when unfilled, make it easy to compare cumulative histograms:"
"Step functions, especially when unfilled, make it easy to compare cumulative histograms:"
]
},
{
Expand Down
18 changes: 18 additions & 0 deletions doc/_docstrings/objects.Est.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,30 @@
"p.add(so.Range(), so.Est(seed=0))"
]
},
{
"cell_type": "markdown",
"id": "df807ef8-b5fb-4eac-b539-1bd4e797ddc2",
"metadata": {},
"source": [
"To compute a weighted estimate (and confidence interval), assign a `weight` variable in the layer where you use the stat:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e4a0594-e1ee-4f72-971e-3763dd626e8b",
"metadata": {},
"outputs": [],
"source": [
"p.add(so.Range(), so.Est(), weight=\"price\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d0c34d7-fb76-44cf-9079-3ec7f45741d0",
"metadata": {},
"outputs": [],
"source": []
}
],
Expand Down
20 changes: 19 additions & 1 deletion doc/_docstrings/objects.Plot.layout.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,28 @@
"p.facet([\"A\", \"B\"], [\"X\", \"Y\"]).layout(engine=\"constrained\")"
]
},
{
"cell_type": "markdown",
"id": "d61054d1-dcef-4e11-9802-394bcc633f9f",
"metadata": {},
"source": [
"With `extent`, you can control the size of the plot relative to the underlying figure. Because the notebook display adapts the figure background to the plot, this appears only to change the plot size in a notebook context. But it can be useful when saving or displaying through a `pyplot` GUI window:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1b5d5969-2925-474f-8e3c-99e4f90a7a2b",
"metadata": {},
"outputs": [],
"source": [
"p.layout(extent=[0, 0, .8, 1]).show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "781ff58c-b805-4e93-8cae-be0442e273ea",
"id": "e5c41b7d-a064-4406-8571-a544b194f3dc",
"metadata": {},
"outputs": [],
"source": []
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"""

# Define replacements (used in whatsnew bullets)
rst_epilog = """
rst_epilog = r"""
.. role:: raw-html(raw)
:format: html
Expand Down
2 changes: 1 addition & 1 deletion doc/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ if you try to reproduce the issue in an example that uses only matplotlib,
so that you can report it in the right place. But it is alright to skip this
step if it's not obvious how to do it.

General support questions are more at home on either `stackoverflow
General support questions are more at home on `stackoverflow
<https://stackoverflow.com/questions/tagged/seaborn/>`_, where there is a
larger audience of people who will see your post and may be able to offer
assistance. Your chance of getting a quick answer will be higher if you include
Expand Down
2 changes: 2 additions & 0 deletions doc/whatsnew/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ v0.13
.. toctree::
:maxdepth: 2

v0.13.2
v0.13.1
v0.13.0

v0.12
Expand Down
22 changes: 22 additions & 0 deletions doc/whatsnew/v0.13.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
v0.13.1 (December 2023)
-----------------------

This is a minor release with some bug fixes and a couple new features. All users are encouraged to update.

- |Feature| Added support for weighted mean estimation (with boostrap CIs) in :func:`lineplot`, :func:`barplot`, :func:`pointplot`, and :class:`objects.Est` (:pr:`3580`, :pr:`3586`).

- |Feature| Added the `extent` option to :meth:`objects.Plot.layout` (:pr:`3552`).

- |Fix| Fixed a regression in v0.13.0 that triggered an exception when working with non-numpy data types (:pr:`3516`).

- |Fix| Fixed a bug in :class:`objects.Plot` so that tick labels are shown for wrapped axes that aren't in the bottom-most row (:pr:`3600`).

- |Fix| Fixed a bug in :func:`catplot` where a blank legend would be added when `hue` was redundantly assigned (:pr:`3540`).

- |Fix| Fixed a bug in :func:`catplot` where the `edgecolor` parameter was ignored with `kind="bar"` (:pr:`3547`).

- |Fix| Fixed a bug in :func:`boxplot` where an exception was raised when using the matplotlib `bootstrap` option (:pr:`3562`).

- |Fix| Fixed a bug in :func:`lineplot` where an exception was raised when `hue` was assigned with an empty dataframe (:pr:`3569`).

- |Fix| Fixed a bug in multiple categorical plots that raised with `hue=None` and `dodge=True`; this is now has no effect (:pr:`3605`).
4 changes: 4 additions & 0 deletions doc/whatsnew/v0.13.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
v0.13.2 (January 2024)
----------------------

This is a minor release containing internal changes that adapt to upcoming deprecations in pandas. All users are encouraged to update.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ requires-python = ">=3.8"
dependencies = [
"numpy>=1.20,!=1.24.0",
"pandas>=1.2",
"matplotlib>=3.3,!=3.6.1",
"matplotlib>=3.4,!=3.6.1",
]

[project.optional-dependencies]
Expand Down Expand Up @@ -66,4 +66,6 @@ exclude = ["doc/_static/*.svg"]
[tool.pytest.ini_options]
filterwarnings = [
"ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning",
"ignore:\\s*Pyarrow will become a required dependency of pandas:DeprecationWarning",
"ignore:datetime.datetime.utcfromtimestamp\\(\\) is deprecated:DeprecationWarning",
]
12 changes: 4 additions & 8 deletions seaborn/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,9 +942,9 @@ def iter_data(

for key in iter_keys:

# Pandas fails with singleton tuple inputs
pd_key = key[0] if len(key) == 1 else key

pd_key = (
key[0] if len(key) == 1 and _version_predates(pd, "2.2.0") else key
)
try:
data_subset = grouped_data.get_group(pd_key)
except KeyError:
Expand Down Expand Up @@ -1160,11 +1160,7 @@ def _attach(
# For categorical y, we want the "first" level to be at the top of the axis
if self.var_types.get("y", None) == "categorical":
for ax in ax_list:
try:
ax.yaxis.set_inverted(True)
except AttributeError: # mpl < 3.1
if not ax.yaxis_inverted():
ax.invert_yaxis()
ax.yaxis.set_inverted(True)

# TODO -- Add axes labels

Expand Down
109 changes: 28 additions & 81 deletions seaborn/_compat.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
from __future__ import annotations
from typing import Literal

import numpy as np
import pandas as pd
import matplotlib as mpl
from matplotlib.figure import Figure
from seaborn.utils import _version_predates


def MarkerStyle(marker=None, fillstyle=None):
"""
Allow MarkerStyle to accept a MarkerStyle object as parameter.
Supports matplotlib < 3.3.0
https://github.com/matplotlib/matplotlib/pull/16692
"""
if isinstance(marker, mpl.markers.MarkerStyle):
if fillstyle is None:
return marker
else:
marker = marker.get_marker()
return mpl.markers.MarkerStyle(marker, fillstyle)


def norm_from_scale(scale, norm):
"""Produce a Normalize object given a Scale and min/max domain limits."""
# This is an internal maplotlib function that simplifies things to access
Expand Down Expand Up @@ -67,66 +56,6 @@ def __call__(self, value, clip=None):
return new_norm


def scale_factory(scale, axis, **kwargs):
"""
Backwards compatability for creation of independent scales.
Matplotlib scales require an Axis object for instantiation on < 3.4.
But the axis is not used, aside from extraction of the axis_name in LogScale.
"""
modify_transform = False
if _version_predates(mpl, "3.4"):
if axis[0] in "xy":
modify_transform = True
axis = axis[0]
base = kwargs.pop("base", None)
if base is not None:
kwargs[f"base{axis}"] = base
nonpos = kwargs.pop("nonpositive", None)
if nonpos is not None:
kwargs[f"nonpos{axis}"] = nonpos

if isinstance(scale, str):
class Axis:
axis_name = axis
axis = Axis()

scale = mpl.scale.scale_factory(scale, axis, **kwargs)

if modify_transform:
transform = scale.get_transform()
transform.base = kwargs.get("base", 10)
if kwargs.get("nonpositive") == "mask":
# Setting a private attribute, but we only get here
# on an old matplotlib, so this won't break going forwards
transform._clip = False

return scale


def set_scale_obj(ax, axis, scale):
"""Handle backwards compatability with setting matplotlib scale."""
if _version_predates(mpl, "3.4"):
# The ability to pass a BaseScale instance to Axes.set_{}scale was added
# to matplotlib in version 3.4.0: GH: matplotlib/matplotlib/pull/19089
# Workaround: use the scale name, which is restrictive only if the user
# wants to define a custom scale; they'll need to update the registry too.
if scale.name is None:
# Hack to support our custom Formatter-less CatScale
return
method = getattr(ax, f"set_{axis}scale")
kws = {}
if scale.name == "function":
trans = scale.get_transform()
kws["functions"] = (trans._forward, trans._inverse)
method(scale.name, **kws)
axis_obj = getattr(ax, f"{axis}axis")
scale.set_default_locators_and_formatters(axis_obj)
else:
ax.set(**{f"{axis}scale": scale})


def get_colormap(name):
"""Handle changes to matplotlib colormap interface in 3.6."""
try:
Expand All @@ -144,19 +73,31 @@ def register_colormap(name, cmap):
mpl.cm.register_cmap(name, cmap)


def set_layout_engine(fig, engine):
def set_layout_engine(
fig: Figure,
engine: Literal["constrained", "compressed", "tight", "none"],
) -> None:
"""Handle changes to auto layout engine interface in 3.6"""
if hasattr(fig, "set_layout_engine"):
fig.set_layout_engine(engine)
else:
# _version_predates(mpl, 3.6)
if engine == "tight":
fig.set_tight_layout(True)
fig.set_tight_layout(True) # type: ignore # predates typing
elif engine == "constrained":
fig.set_constrained_layout(True)
fig.set_constrained_layout(True) # type: ignore
elif engine == "none":
fig.set_tight_layout(False)
fig.set_constrained_layout(False)
fig.set_tight_layout(False) # type: ignore
fig.set_constrained_layout(False) # type: ignore


def get_layout_engine(fig: Figure) -> mpl.layout_engine.LayoutEngine | None:
"""Handle changes to auto layout engine interface in 3.6"""
if hasattr(fig, "get_layout_engine"):
return fig.get_layout_engine()
else:
# _version_predates(mpl, 3.6)
return None


def share_axis(ax0, ax1, which):
Expand All @@ -174,3 +115,9 @@ def get_legend_handles(legend):
return legend.legendHandles
else:
return legend.legend_handles


def groupby_apply_include_groups(val):
if _version_predates(pd, "2.2.0"):
return {}
return {"include_groups": val}

0 comments on commit 56aced5

Please sign in to comment.