Skip to content

Commit 578a619

Browse files
jbrockmendelKevin D Smith
authored and
Kevin D Smith
committed
TYP: annotations in pandas.plotting (pandas-dev#35935)
1 parent 7853c21 commit 578a619

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

pandas/plotting/_matplotlib/converter.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import contextlib
22
import datetime as pydt
3-
from datetime import datetime, timedelta
3+
from datetime import datetime, timedelta, tzinfo
44
import functools
5+
from typing import Optional, Tuple
56

67
from dateutil.relativedelta import relativedelta
78
import matplotlib.dates as dates
@@ -152,7 +153,7 @@ def axisinfo(unit, axis):
152153
return units.AxisInfo(majloc=majloc, majfmt=majfmt, label="time")
153154

154155
@staticmethod
155-
def default_units(x, axis):
156+
def default_units(x, axis) -> str:
156157
return "time"
157158

158159

@@ -421,7 +422,7 @@ def autoscale(self):
421422
return self.nonsingular(vmin, vmax)
422423

423424

424-
def _from_ordinal(x, tz=None):
425+
def _from_ordinal(x, tz: Optional[tzinfo] = None) -> datetime:
425426
ix = int(x)
426427
dt = datetime.fromordinal(ix)
427428
remainder = float(x) - ix
@@ -450,7 +451,7 @@ def _from_ordinal(x, tz=None):
450451
# -------------------------------------------------------------------------
451452

452453

453-
def _get_default_annual_spacing(nyears):
454+
def _get_default_annual_spacing(nyears) -> Tuple[int, int]:
454455
"""
455456
Returns a default spacing between consecutive ticks for annual data.
456457
"""

pandas/plotting/_matplotlib/timeseries.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ def _maybe_resample(series: "Series", ax, kwargs):
6262
return freq, series
6363

6464

65-
def _is_sub(f1, f2):
65+
def _is_sub(f1: str, f2: str) -> bool:
6666
return (f1.startswith("W") and is_subperiod("D", f2)) or (
6767
f2.startswith("W") and is_subperiod(f1, "D")
6868
)
6969

7070

71-
def _is_sup(f1, f2):
71+
def _is_sup(f1: str, f2: str) -> bool:
7272
return (f1.startswith("W") and is_superperiod("D", f2)) or (
7373
f2.startswith("W") and is_superperiod(f1, "D")
7474
)

pandas/plotting/_matplotlib/tools.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
# being a bit too dynamic
22
from math import ceil
3+
from typing import TYPE_CHECKING, Tuple
34
import warnings
45

56
import matplotlib.table
67
import matplotlib.ticker as ticker
78
import numpy as np
89

10+
from pandas._typing import FrameOrSeries
11+
912
from pandas.core.dtypes.common import is_list_like
1013
from pandas.core.dtypes.generic import ABCDataFrame, ABCIndexClass, ABCSeries
1114

1215
from pandas.plotting._matplotlib import compat
1316

17+
if TYPE_CHECKING:
18+
from matplotlib.table import Table
19+
1420

1521
def format_date_labels(ax, rot):
1622
# mini version of autofmt_xdate
@@ -21,7 +27,7 @@ def format_date_labels(ax, rot):
2127
fig.subplots_adjust(bottom=0.2)
2228

2329

24-
def table(ax, data, rowLabels=None, colLabels=None, **kwargs):
30+
def table(ax, data: FrameOrSeries, rowLabels=None, colLabels=None, **kwargs) -> "Table":
2531
if isinstance(data, ABCSeries):
2632
data = data.to_frame()
2733
elif isinstance(data, ABCDataFrame):
@@ -43,7 +49,7 @@ def table(ax, data, rowLabels=None, colLabels=None, **kwargs):
4349
return table
4450

4551

46-
def _get_layout(nplots, layout=None, layout_type="box"):
52+
def _get_layout(nplots: int, layout=None, layout_type: str = "box") -> Tuple[int, int]:
4753
if layout is not None:
4854
if not isinstance(layout, (tuple, list)) or len(layout) != 2:
4955
raise ValueError("Layout must be a tuple of (rows, columns)")
@@ -92,14 +98,14 @@ def _get_layout(nplots, layout=None, layout_type="box"):
9298

9399

94100
def _subplots(
95-
naxes=None,
96-
sharex=False,
97-
sharey=False,
98-
squeeze=True,
101+
naxes: int,
102+
sharex: bool = False,
103+
sharey: bool = False,
104+
squeeze: bool = True,
99105
subplot_kw=None,
100106
ax=None,
101107
layout=None,
102-
layout_type="box",
108+
layout_type: str = "box",
103109
**fig_kw,
104110
):
105111
"""
@@ -369,7 +375,7 @@ def _get_all_lines(ax):
369375
return lines
370376

371377

372-
def _get_xlim(lines):
378+
def _get_xlim(lines) -> Tuple[float, float]:
373379
left, right = np.inf, -np.inf
374380
for l in lines:
375381
x = l.get_xdata(orig=False)

0 commit comments

Comments
 (0)