Skip to content

Commit a136077

Browse files
committed
ruff
1 parent cd5ac37 commit a136077

62 files changed

Lines changed: 279 additions & 261 deletions

Some content is hidden

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

ggplotly/__init__.py

Lines changed: 74 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,97 @@
11
# __init__.py
22

3-
from .ggplot import ggplot
4-
from .ggtitle import ggtitle
53
from .aes import aes
6-
from .themes import (
7-
theme_default,
8-
theme,
9-
theme_ggplot2,
10-
theme_nytimes,
11-
theme_minimal,
12-
theme_bbc,
13-
# theme_bw,
14-
theme_dark,
15-
theme_classic,
16-
theme_custom,
17-
element_text,
18-
element_line,
19-
element_rect,
20-
)
21-
from .facets import Facet, facet_wrap, facet_grid, label_value, label_both
22-
from .coords import Coord, coord_flip, coord_polar, coord_cartesian, coord_sf
23-
from .limits import xlim, ylim, lims
4+
from .coords import Coord, coord_cartesian, coord_flip, coord_polar, coord_sf
5+
from .datasets import data
6+
from .facets import Facet, facet_grid, facet_wrap, label_both, label_value
247
from .geoms import (
25-
geom_point,
26-
geom_line,
27-
geom_path,
8+
geom_abline,
9+
geom_area,
2810
geom_bar,
29-
geom_col,
30-
geom_histogram,
3111
geom_boxplot,
32-
geom_smooth,
33-
geom_area,
12+
geom_candlestick,
13+
geom_col,
14+
geom_contour,
15+
geom_contour_filled,
3416
geom_density,
35-
geom_violin,
36-
geom_ribbon,
37-
geom_tile,
38-
geom_text,
17+
geom_edgebundle,
3918
geom_errorbar,
40-
geom_segment,
41-
geom_step,
42-
geom_vline,
19+
geom_histogram,
4320
geom_hline,
44-
geom_edgebundle,
45-
geom_searoute,
4621
geom_jitter,
47-
geom_rug,
48-
geom_abline,
49-
geom_contour,
50-
geom_contour_filled,
22+
geom_line,
5123
geom_map,
52-
geom_sf,
53-
geom_range,
24+
geom_ohlc,
25+
geom_path,
26+
geom_point,
5427
geom_point_3d,
28+
geom_range,
29+
geom_ribbon,
30+
geom_rug,
31+
geom_searoute,
32+
geom_segment,
33+
geom_sf,
34+
geom_smooth,
35+
geom_step,
5536
geom_surface,
37+
geom_text,
38+
geom_tile,
39+
geom_violin,
40+
geom_vline,
5641
geom_wireframe,
57-
geom_candlestick,
58-
geom_ohlc,
5942
)
43+
from .ggplot import ggplot
44+
from .ggtitle import ggtitle
45+
from .guides import annotate, guide_colorbar, guide_legend, guides, labs
46+
from .layer import Layer, layer
47+
from .limits import lims, xlim, ylim
48+
from .map_data import map_data
49+
from .positions import position_dodge, position_jitter, position_stack
6050
from .scales import (
61-
scale_x_continuous,
62-
scale_y_continuous,
63-
scale_color_manual,
6451
scale_color_brewer,
52+
scale_color_gradient,
53+
scale_color_manual,
54+
scale_fill_brewer,
6555
scale_fill_gradient,
6656
scale_fill_manual,
67-
scale_fill_brewer,
6857
scale_fill_viridis_c,
6958
scale_shape_manual,
7059
scale_size,
71-
scale_x_log10,
72-
scale_y_log10,
60+
scale_x_continuous,
7361
scale_x_date,
7462
scale_x_datetime,
75-
scale_x_rangeslider,
63+
scale_x_log10,
7664
scale_x_rangeselector,
77-
scale_color_gradient,
65+
scale_x_rangeslider,
66+
scale_y_continuous,
67+
scale_y_log10,
68+
)
69+
from .stats import (
70+
stat_bin,
71+
stat_contour,
72+
stat_count,
73+
stat_density,
74+
stat_ecdf,
75+
stat_identity,
76+
stat_smooth,
77+
stat_summary,
78+
)
79+
from .themes import (
80+
element_line,
81+
element_rect,
82+
element_text,
83+
theme,
84+
theme_bbc,
85+
theme_classic,
86+
theme_custom,
87+
# theme_bw,
88+
theme_dark,
89+
theme_default,
90+
theme_ggplot2,
91+
theme_minimal,
92+
theme_nytimes,
7893
)
79-
from .guides import labs, annotate, guides, guide_legend, guide_colorbar
80-
from .positions import position_dodge, position_jitter, position_stack
8194
from .utils import ggsave, ggsize
82-
from .stats import *
83-
from .datasets import data
84-
from .map_data import map_data
85-
from .layer import Layer, layer
8695

8796
__all__ = [
8897
"ggplot",
@@ -175,8 +184,14 @@
175184
"scale_x_rangeslider",
176185
"scale_x_rangeselector",
177186
"scale_color_gradient",
178-
"stat_count",
187+
"stat_identity",
188+
"stat_smooth",
179189
"stat_bin",
190+
"stat_density",
191+
"stat_ecdf",
192+
"stat_count",
193+
"stat_summary",
194+
"stat_contour",
180195
"data",
181196
"map_data",
182197
"Layer",

ggplotly/aesthetic_mapper.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
This module provides a clean interface for resolving aesthetic mappings
66
and determining whether aesthetic values are column references or literal values.
77
"""
8+
from __future__ import annotations
89

9-
import pandas as pd
10-
import plotly.express as px
1110
from functools import lru_cache
12-
from typing import Any, Dict, Optional, Union, Tuple
11+
from typing import Any
12+
13+
import pandas as pd
1314

14-
from .constants import SHAPE_PALETTE, get_color_palette as _get_color_palette
15-
from .exceptions import ColumnNotFoundError, InvalidColorError
15+
from .constants import SHAPE_PALETTE
16+
from .constants import get_color_palette as _get_color_palette
17+
from .exceptions import ColumnNotFoundError
1618

1719

1820
# Module-level cache for color conversions (expensive Plotly operations)
@@ -103,8 +105,8 @@ class AestheticMapper:
103105
- Literal values (colors, sizes, etc. to be used directly)
104106
"""
105107

106-
def __init__(self, data: pd.DataFrame, mapping: Dict[str, Any], params: Dict[str, Any], theme=None,
107-
global_color_map: Dict[Any, str] = None, global_shape_map: Dict[Any, str] = None,
108+
def __init__(self, data: pd.DataFrame, mapping: dict[str, Any], params: dict[str, Any], theme=None,
109+
global_color_map: dict[Any, str] = None, global_shape_map: dict[Any, str] = None,
108110
validate: bool = True):
109111
"""
110112
Initialize the aesthetic mapper.
@@ -171,8 +173,8 @@ def validate_column(self, column: str, aesthetic: str = None) -> None:
171173
"""
172174
if column not in self._column_set:
173175
raise ColumnNotFoundError(column, list(self.data.columns), aesthetic)
174-
175-
def resolve_aesthetic(self, aesthetic: str) -> Tuple[Any, Optional[pd.Series], Optional[Dict]]:
176+
177+
def resolve_aesthetic(self, aesthetic: str) -> tuple[Any, pd.Series | None, dict | None]:
176178
"""
177179
Resolve an aesthetic from both mapping and params.
178180
@@ -202,7 +204,7 @@ def resolve_aesthetic(self, aesthetic: str) -> Tuple[Any, Optional[pd.Series], O
202204
else:
203205
# It's a literal value
204206
return value, None, None
205-
207+
206208
def _is_continuous(self, series: pd.Series) -> bool:
207209
"""
208210
Determine if a series should be treated as continuous (numeric) or categorical.
@@ -237,7 +239,7 @@ def _is_continuous(self, series: pd.Series) -> bool:
237239

238240
return False
239241

240-
def _create_color_map(self, series: pd.Series) -> Dict[Any, str]:
242+
def _create_color_map(self, series: pd.Series) -> dict[Any, str]:
241243
"""
242244
Create a mapping from unique values to colors.
243245
@@ -261,7 +263,7 @@ def _create_color_map(self, series: pd.Series) -> Dict[Any, str]:
261263

262264
return color_map
263265

264-
def _create_shape_map(self, series: pd.Series) -> Dict[Any, str]:
266+
def _create_shape_map(self, series: pd.Series) -> dict[Any, str]:
265267
"""
266268
Create a mapping from unique values to marker shapes.
267269
@@ -278,8 +280,8 @@ def _create_shape_map(self, series: pd.Series) -> Dict[Any, str]:
278280
shape_map[val] = SHAPE_PALETTE[i % len(SHAPE_PALETTE)]
279281

280282
return shape_map
281-
282-
def get_style_properties(self) -> Dict[str, Any]:
283+
284+
def get_style_properties(self) -> dict[str, Any]:
283285
"""
284286
Extract all relevant style properties for a geom.
285287
@@ -368,8 +370,8 @@ def get_style_properties(self) -> Dict[str, Any]:
368370
# Cache the result for subsequent calls
369371
self._style_props_cache = result
370372
return result
371-
372-
def get_color_for_value(self, value_key: Any, style_props: Dict[str, Any] = None,
373+
374+
def get_color_for_value(self, value_key: Any, style_props: dict[str, Any] = None,
373375
prefer_fill: bool = False) -> str:
374376
"""
375377
Get the resolved color for a specific value/group.
@@ -411,7 +413,7 @@ def get_color_for_value(self, value_key: Any, style_props: Dict[str, Any] = None
411413

412414
return style_props['default_color']
413415

414-
def get_color_with_alpha(self, value_key: Any = None, style_props: Dict[str, Any] = None,
416+
def get_color_with_alpha(self, value_key: Any = None, style_props: dict[str, Any] = None,
415417
prefer_fill: bool = False, alpha_override: float = None) -> str:
416418
"""
417419
Get color with alpha channel as RGBA string.
@@ -457,7 +459,7 @@ def _color_to_rgba(self, color: str, alpha: float) -> str:
457459
return _cached_color_to_rgba(color, alpha)
458460

459461
def apply_style_to_trace(self, trace_kwargs: dict, style_props: dict,
460-
target_mapping: dict, value_key: Optional[Any] = None) -> dict:
462+
target_mapping: dict, value_key: Any | None = None) -> dict:
461463
"""
462464
Apply style properties to a trace dictionary based on target mapping.
463465
@@ -496,17 +498,17 @@ def apply_style_to_trace(self, trace_kwargs: dict, style_props: dict,
496498
return trace_kwargs
497499

498500

499-
def create_aesthetic_mapper(data: pd.DataFrame, mapping: Dict[str, Any],
500-
params: Dict[str, Any], theme=None) -> AestheticMapper:
501+
def create_aesthetic_mapper(data: pd.DataFrame, mapping: dict[str, Any],
502+
params: dict[str, Any], theme=None) -> AestheticMapper:
501503
"""
502504
Factory function to create an AestheticMapper instance.
503-
505+
504506
Parameters:
505507
data: The DataFrame containing the plot data
506508
mapping: Dictionary of aesthetic mappings from aes()
507509
params: Dictionary of parameters passed to the geom
508510
theme: Optional theme object
509-
511+
510512
Returns:
511513
AestheticMapper instance
512514
"""

ggplotly/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import plotly.express as px
99

10-
1110
# Default shape palette matching ggplot2's defaults
1211
# Maps to Plotly marker symbols
1312
# See: https://plotly.com/python/marker-style/

ggplotly/coords/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# coords/__init__.py
22

33
from .coord_base import Coord
4+
from .coord_cartesian import coord_cartesian
45
from .coord_flip import coord_flip
56
from .coord_polar import coord_polar
6-
from .coord_cartesian import coord_cartesian
77
from .coord_sf import coord_sf
88

99
__all__ = ["Coord", "coord_flip", "coord_polar", "coord_cartesian", "coord_sf"]

ggplotly/coords/coord_polar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import numpy as np
44
import plotly.graph_objects as go
5+
56
from .coord_base import Coord
67

78

ggplotly/data_utils.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@
2828
>>> df.index.name = 'time'
2929
>>> ggplot(df, aes(y='y')) + geom_point() # x-axis labeled 'time'
3030
"""
31+
from __future__ import annotations
32+
33+
from typing import Any
3134

3235
import pandas as pd
33-
from typing import Tuple, Dict, Any, Optional
3436

3537
# Reserved column name for index data
3638
INDEX_COLUMN = '_ggplotly_index'
3739

3840

39-
def normalize_data(data, mapping: Dict[str, Any]) -> Tuple[Optional[pd.DataFrame], Dict[str, Any], Optional[str]]:
41+
def normalize_data(data, mapping: dict[str, Any]) -> tuple[pd.DataFrame | None, dict[str, Any], str | None]:
4042
"""
4143
Normalize input data and mapping for ggplotly consumption.
4244
@@ -94,7 +96,7 @@ def normalize_data(data, mapping: Dict[str, Any]) -> Tuple[Optional[pd.DataFrame
9496
return data, mapping, index_name
9597

9698

97-
def _normalize_series(series: pd.Series, mapping: Dict[str, Any]) -> Tuple[pd.DataFrame, Dict[str, Any], str]:
99+
def _normalize_series(series: pd.Series, mapping: dict[str, Any]) -> tuple[pd.DataFrame, dict[str, Any], str]:
98100
"""
99101
Convert a Series to a DataFrame for plotting.
100102
@@ -131,7 +133,7 @@ def _normalize_series(series: pd.Series, mapping: Dict[str, Any]) -> Tuple[pd.Da
131133
return df, mapping, index_name
132134

133135

134-
def _handle_index_references(data: pd.DataFrame, mapping: Dict[str, Any]) -> Tuple[pd.DataFrame, Dict[str, Any]]:
136+
def _handle_index_references(data: pd.DataFrame, mapping: dict[str, Any]) -> tuple[pd.DataFrame, dict[str, Any]]:
135137
"""
136138
Handle 'index' keyword in aesthetic mappings.
137139
@@ -170,7 +172,7 @@ def _handle_index_references(data: pd.DataFrame, mapping: Dict[str, Any]) -> Tup
170172
return data, mapping
171173

172174

173-
def _auto_populate_x(data: pd.DataFrame, mapping: Dict[str, Any]) -> Tuple[pd.DataFrame, Dict[str, Any]]:
175+
def _auto_populate_x(data: pd.DataFrame, mapping: dict[str, Any]) -> tuple[pd.DataFrame, dict[str, Any]]:
174176
"""
175177
Auto-populate x aesthetic from index when not specified.
176178
@@ -203,7 +205,7 @@ def _auto_populate_x(data: pd.DataFrame, mapping: Dict[str, Any]) -> Tuple[pd.Da
203205
return data, mapping
204206

205207

206-
def get_index_label(index_name: Optional[str]) -> str:
208+
def get_index_label(index_name: str | None) -> str:
207209
"""
208210
Get the appropriate label for the index axis.
209211

0 commit comments

Comments
 (0)