Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Python3.10-3.12 compatibility #1

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ on: [push, pull_request]

jobs:
test-code:
name : test ${{ matrix.os }} / ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu, macos, windows]
python-version: ['3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
Expand All @@ -14,7 +19,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: ${{ matrix.python-version }}

- name: Set up Poetry
uses: abatilo/actions-poetry@v2
Expand Down
13 changes: 8 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
default_language_version:
python: python3.11

# Built-in hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -22,21 +25,21 @@ repos:

# Pyupgrade
- repo: https://github.com/asottile/pyupgrade
rev: v3.13.0
rev: v3.15.0
hooks:
- id: pyupgrade

# Ruff
# We put this hook before Black hook, as autofix results may need to be reformatted by Black linter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
rev: v0.1.6
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
exclude: ^(tests|docs)/
# Black
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.11.0
hooks:
- id: black
# Isort
Expand All @@ -47,7 +50,7 @@ repos:
exclude: ^.*/?setup\.py$
# MyPy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1 # Use the sha / tag you want to point at
rev: v1.7.1 # Use the sha / tag you want to point at
hooks:
- id: mypy
args: [--ignore-missing-imports]
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
PROJECT_NAME=statsplotly

# Python env
PYTHON_SHELL_VERSION := $(shell python --version | cut -d " " -f 2)
POETRY_AVAILABLE := $(shell which poetry > /dev/null && echo 1 || echo 0)
Expand Down Expand Up @@ -63,7 +65,7 @@ pre-commit: set-pre-commit run-pre-commit

# Documentation
update-doc:
@poetry run sphinx-apidoc --module-first --no-toc -o docs/source statsplotly
@poetry run sphinx-apidoc --module-first --no-toc -o docs/source $(PROJECT_NAME)

build-doc:
@poetry run sphinx-build docs ./docs/_build/html/
Expand Down
7 changes: 7 additions & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 0.1.5
=============
**2023-11-25**

The 0.1.5 ensures compatibility with Python>=3.10.


Version 0.1.4
=============
**2023-09-27**
Expand Down
1,956 changes: 988 additions & 968 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homepage = "https://github.com/parici75/statsplotly"
documentation = "https://parici75.github.io/statsplotly/"

[tool.poetry.dependencies]
python = ">=3.11, <3.13"
python = ">=3.10, <3.13"
pydantic = "^2.4"
seaborn = "^0.12.2"
scipy = "^1.11.1"
Expand All @@ -19,9 +19,9 @@ jupyter = "^1.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
mypy = "v1.5.1"
ruff = "^0.0.276"
black = "^23.3.0"
mypy = "^1.7.1"
ruff = "^0.1.6"
black = "^23.11.0"
isort = "^5.12.0"
pyupgrade = "^3.8.0"
pre-commit = "^3.3.3"
Expand Down
1 change: 1 addition & 0 deletions statsplotly/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Custom exceptions."""

from enum import Enum
from typing import Any

Expand Down
23 changes: 10 additions & 13 deletions statsplotly/plot_specifiers/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,19 @@ def validate_axis_range_format(
cls, value: list[float | str] | None
) -> list[float | str] | None:
if value is not None:
if any(isinstance(limit, str) for limit in value):
try:
[parse_date(limit) for limit in value if limit is not None]
except Exception as exc:
raise ValueError("Axis range must be numeric or `datetime`") from exc
try:
[parse_date(limit) for limit in value if isinstance(limit, str)]
except Exception as exc:
raise ValueError("Axis range must be numeric or `datetime`") from exc
return value

def get_axes_range(self) -> list[Any] | None:
values_span = np.concatenate(
[
data
for trace in self.traces
for data in [trace.x_values, trace.y_values, trace.z_values]
if data is not None
]
)
values_span = np.concatenate([
data
for trace in self.traces
for data in [trace.x_values, trace.y_values, trace.z_values]
if data is not None
])
axes_span = [
axis_span
for axis_span in [self.x_range, self.y_range, self.z_range]
Expand Down
10 changes: 4 additions & 6 deletions statsplotly/plotting/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,12 +880,10 @@ def distplot(
)
# Hide axes
axis_idx = str(row * subplot_col) if row * subplot_col > 1 else ""
fig.update_layout(
{
f"xaxis{axis_idx}": {"visible": False},
f"yaxis{axis_idx}": {"visible": False},
}
)
fig.update_layout({
f"xaxis{axis_idx}": {"visible": False},
f"yaxis{axis_idx}": {"visible": False},
})

# Create fig
fig = create_fig(
Expand Down
60 changes: 28 additions & 32 deletions statsplotly/utils/figure_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def create_fig( # noqa: PLR0912 PLR0913 C901
axis_number = axis_number_pattern.group()
if (scaleanchor := layout_dict[axis_ref].get("scaleanchor")) is not None:
scaleanchor_root = re.sub(r"\d", axis_number_pattern.group(), scaleanchor)
layout_dict[axis_ref].update(
{"scaleanchor": f"{scaleanchor_root}{axis_number}"}
)
layout_dict[axis_ref].update({
"scaleanchor": f"{scaleanchor_root}{axis_number}"
})

# Remove axes titles
if row < len(fig._grid_ref):
Expand All @@ -105,41 +105,37 @@ def create_fig( # noqa: PLR0912 PLR0913 C901
def _clean_col_titles(titles: list[str], fig: go.Figure) -> go.Figure:
for i, col_title in enumerate(titles, 1):
x_unit = 1 / len(fig._grid_ref[0])
fig.add_annotation(
{
"font": {"size": 16},
"showarrow": False,
"text": col_title,
"x": x_unit * i - x_unit / 2,
"xanchor": "center",
"xref": "paper",
"y": 1,
"yanchor": "top",
"yref": "paper",
"yshift": +30,
}
)
fig.add_annotation({
"font": {"size": 16},
"showarrow": False,
"text": col_title,
"x": x_unit * i - x_unit / 2,
"xanchor": "center",
"xref": "paper",
"y": 1,
"yanchor": "top",
"yref": "paper",
"yshift": +30,
})
return fig


def _clean_row_titles(titles: list[str], fig: go.Figure) -> go.Figure:
for i, row_title in enumerate(titles[::-1], 1):
y_unit = 1 / len(fig._grid_ref)
fig.add_annotation(
{
"font": {"size": 16},
"showarrow": False,
"text": row_title,
"x": 0,
"textangle": 0,
"xanchor": "right",
"xref": "paper",
"xshift": -40,
"y": y_unit * i - y_unit / 2,
"yanchor": "middle",
"yref": "paper",
}
)
fig.add_annotation({
"font": {"size": 16},
"showarrow": False,
"text": row_title,
"x": 0,
"textangle": 0,
"xanchor": "right",
"xref": "paper",
"xshift": -40,
"y": y_unit * i - y_unit / 2,
"yanchor": "middle",
"yref": "paper",
})

# Add some left margin
try:
Expand Down
40 changes: 16 additions & 24 deletions statsplotly/utils/layout_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ def adjust_jointplot_legends(
# Separate legend groups if we have only one slice
if len(slices_marginal_traces) == 1:
for trace in slices_marginal_traces:
slices_marginal_traces[trace].update(
{
"legendgroup": " ".join(
(slices_marginal_traces[trace].legendgroup, "marginal")
)
}
)
slices_marginal_traces[trace].update({
"legendgroup": " ".join((slices_marginal_traces[trace].legendgroup, "marginal"))
})


def add_update_menu(
Expand Down Expand Up @@ -139,27 +135,23 @@ def smart_title(title_string: str) -> str:
title_string = title_string.strip()
if len(title_string) == 0:
return title_string
return " ".join(
[
(
"".join([word[0].upper(), word[1:]])
if (len(word) >= constants.MIN_CAPITALIZE_LENGTH)
and not (any(letter.isupper() for letter in word))
else word
)
for word in re.split(" |_", title_string)
]
)
return " ".join([
(
"".join([word[0].upper(), word[1:]])
if (len(word) >= constants.MIN_CAPITALIZE_LENGTH)
and not (any(letter.isupper() for letter in word))
else word
)
for word in re.split(" |_", title_string)
])


def smart_legend(legend_string: str) -> str:
"""Cleans and capitalizes axis legends for figure."""
legend_string = legend_string.strip()
if len(legend_string) == 0:
return legend_string
return " ".join(
[
"".join([w[0].upper(), w[1:]]) if i == 0 else w
for i, w in enumerate(re.split("_", legend_string))
]
)
return " ".join([
"".join([w[0].upper(), w[1:]]) if i == 0 else w
for i, w in enumerate(re.split("_", legend_string))
])