Skip to content

Commit d8cdcb5

Browse files
authored
fix matplotlib imports, pd.util (#776)
* fix matplotlib imports, pd.util * add todo for pd.util
1 parent 6bb1215 commit d8cdcb5

File tree

4 files changed

+58
-57
lines changed

4 files changed

+58
-57
lines changed

pandas-stubs/plotting/_core.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class PlotAccessor:
239239
**kwargs: Any,
240240
) -> pd.Series: ...
241241
@overload
242-
def line(
242+
def line( # type: ignore[misc]
243243
self,
244244
x: Hashable | None = ...,
245245
y: Hashable | None = ...,
@@ -257,7 +257,7 @@ class PlotAccessor:
257257
**kwargs,
258258
) -> npt.NDArray[np.object_]: ...
259259
@overload
260-
def bar(
260+
def bar( # type: ignore[misc]
261261
self,
262262
x: Hashable | None = ...,
263263
y: Hashable | None = ...,
@@ -275,7 +275,7 @@ class PlotAccessor:
275275
**kwargs,
276276
) -> npt.NDArray[np.object_]: ...
277277
@overload
278-
def barh(
278+
def barh( # type: ignore[misc]
279279
self,
280280
x: Hashable | None = ...,
281281
y: Hashable | None = ...,
@@ -293,7 +293,7 @@ class PlotAccessor:
293293
**kwargs,
294294
) -> npt.NDArray[np.object_]: ...
295295
@overload
296-
def box(
296+
def box( # type: ignore[misc]
297297
self,
298298
by: Hashable | list[HashableT] | None = ...,
299299
subplots: Literal[False] | None = ...,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mypy = "1.5.1"
3939
pandas = "2.0.3"
4040
pyarrow = ">=10.0.1"
4141
pytest = ">=7.1.2"
42-
pyright = ">= 1.1.322"
42+
pyright = ">= 1.1.327"
4343
poethepoet = ">=0.16.5"
4444
loguru = ">=0.6.0"
4545
typing-extensions = ">=4.4.0"

tests/test_pandas.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import pandas as pd
1414
from pandas import Grouper
1515
from pandas.api.extensions import ExtensionArray
16+
import pandas.util as pdutil
17+
18+
# TODO: github.com/pandas-dev/pandas/issues/55023
1619
import pytest
1720
from typing_extensions import assert_type
1821

@@ -520,10 +523,10 @@ def test_arrow_dtype() -> None:
520523

521524
def test_hashing():
522525
a = np.array([1, 2, 3])
523-
check(assert_type(pd.util.hash_array(a), npt.NDArray[np.uint64]), np.ndarray)
526+
check(assert_type(pdutil.hash_array(a), npt.NDArray[np.uint64]), np.ndarray)
524527
check(
525528
assert_type(
526-
pd.util.hash_array(a, encoding="latin1", hash_key="1", categorize=True),
529+
pdutil.hash_array(a, encoding="latin1", hash_key="1", categorize=True),
527530
npt.NDArray[np.uint64],
528531
),
529532
np.ndarray,
@@ -532,12 +535,12 @@ def test_hashing():
532535
b = pd.Series(a)
533536
c = pd.DataFrame({"a": a, "b": a})
534537
d = pd.Index(b)
535-
check(assert_type(pd.util.hash_pandas_object(b), pd.Series), pd.Series)
536-
check(assert_type(pd.util.hash_pandas_object(c), pd.Series), pd.Series)
537-
check(assert_type(pd.util.hash_pandas_object(d), pd.Series), pd.Series)
538+
check(assert_type(pdutil.hash_pandas_object(b), pd.Series), pd.Series)
539+
check(assert_type(pdutil.hash_pandas_object(c), pd.Series), pd.Series)
540+
check(assert_type(pdutil.hash_pandas_object(d), pd.Series), pd.Series)
538541
check(
539542
assert_type(
540-
pd.util.hash_pandas_object(
543+
pdutil.hash_pandas_object(
541544
d, index=True, encoding="latin1", hash_key="apple", categorize=True
542545
),
543546
pd.Series,

tests/test_plotting.py

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import io
22
from typing import Any
33

4+
from matplotlib.axes import Axes
5+
from matplotlib.figure import Figure
46
import matplotlib.pyplot as plt
57
from matplotlib.table import Table
68
import numpy as np
@@ -178,26 +180,26 @@ def close_figures():
178180

179181

180182
def test_andrews_curves(close_figures) -> None:
181-
check(assert_type(pd.plotting.andrews_curves(IRIS_DF, "Name"), plt.Axes), plt.Axes)
183+
check(assert_type(pd.plotting.andrews_curves(IRIS_DF, "Name"), Axes), Axes)
182184

183185

184186
def test_autocorrelation_plot(close_figures) -> None:
185187
spacing = np.linspace(-9 * np.pi, 9 * np.pi, num=1000)
186188
s = pd.Series(0.7 * np.random.rand(1000) + 0.3 * np.sin(spacing))
187-
check(assert_type(pd.plotting.autocorrelation_plot(s), plt.Axes), plt.Axes)
189+
check(assert_type(pd.plotting.autocorrelation_plot(s), Axes), Axes)
188190

189191

190192
def test_bootstrap_plot(close_figures) -> None:
191193
s = pd.Series(np.random.uniform(size=100))
192-
check(assert_type(pd.plotting.bootstrap_plot(s), plt.Figure), plt.Figure)
194+
check(assert_type(pd.plotting.bootstrap_plot(s), Figure), Figure)
193195

194196

195197
def test_boxplot(close_figures) -> None:
196198
np.random.seed(1234)
197199
df = pd.DataFrame(np.random.randn(10, 4), columns=["Col1", "Col2", "Col3", "Col4"])
198200
check(
199-
assert_type(pd.plotting.boxplot(df, column=["Col1", "Col2", "Col3"]), plt.Axes),
200-
plt.Axes,
201+
assert_type(pd.plotting.boxplot(df, column=["Col1", "Col2", "Col3"]), Axes),
202+
Axes,
201203
)
202204

203205

@@ -210,7 +212,7 @@ def test_lag_plot(close_figures) -> None:
210212
np.random.seed(5)
211213
x = np.cumsum(np.random.normal(loc=1, scale=5, size=50))
212214
s = pd.Series(x)
213-
check(assert_type(pd.plotting.lag_plot(s, lag=1), plt.Axes), plt.Axes)
215+
check(assert_type(pd.plotting.lag_plot(s, lag=1), Axes), Axes)
214216

215217

216218
def test_plot_parallel_coordinates(close_figures) -> None:
@@ -219,9 +221,9 @@ def test_plot_parallel_coordinates(close_figures) -> None:
219221
pd.plotting.parallel_coordinates(
220222
IRIS_DF, "Name", color=("#556270", "#4ECDC4", "#C7F464")
221223
),
222-
plt.Axes,
224+
Axes,
223225
),
224-
plt.Axes,
226+
Axes,
225227
)
226228

227229

@@ -250,7 +252,7 @@ def test_radviz(close_figures) -> None:
250252
],
251253
}
252254
)
253-
check(assert_type(pd.plotting.radviz(df, "Category"), plt.Axes), plt.Axes)
255+
check(assert_type(pd.plotting.radviz(df, "Category"), Axes), Axes)
254256

255257

256258
def test_scatter_matrix(close_figures) -> None:
@@ -271,9 +273,9 @@ def test_table(close_figures) -> None:
271273

272274

273275
def test_plot_line():
274-
check(assert_type(IRIS_DF.plot(), plt.Axes), plt.Axes)
275-
check(assert_type(IRIS_DF.plot.line(), plt.Axes), plt.Axes)
276-
check(assert_type(IRIS_DF.plot(kind="line"), plt.Axes), plt.Axes)
276+
check(assert_type(IRIS_DF.plot(), Axes), Axes)
277+
check(assert_type(IRIS_DF.plot.line(), Axes), Axes)
278+
check(assert_type(IRIS_DF.plot(kind="line"), Axes), Axes)
277279
check(
278280
assert_type(
279281
IRIS_DF.plot.line(subplots=True),
@@ -291,8 +293,8 @@ def test_plot_line():
291293

292294

293295
def test_plot_area(close_figures) -> None:
294-
check(assert_type(IRIS_DF.plot.area(), plt.Axes), plt.Axes)
295-
check(assert_type(IRIS_DF.plot(kind="area"), plt.Axes), plt.Axes)
296+
check(assert_type(IRIS_DF.plot.area(), Axes), Axes)
297+
check(assert_type(IRIS_DF.plot(kind="area"), Axes), Axes)
296298
check(
297299
assert_type(
298300
IRIS_DF.plot.area(subplots=True),
@@ -310,8 +312,8 @@ def test_plot_area(close_figures) -> None:
310312

311313

312314
def test_plot_bar(close_figures) -> None:
313-
check(assert_type(IRIS_DF.plot.bar(), plt.Axes), plt.Axes)
314-
check(assert_type(IRIS_DF.plot(kind="bar"), plt.Axes), plt.Axes)
315+
check(assert_type(IRIS_DF.plot.bar(), Axes), Axes)
316+
check(assert_type(IRIS_DF.plot(kind="bar"), Axes), Axes)
315317
check(
316318
assert_type(
317319
IRIS_DF.plot.bar(subplots=True),
@@ -329,8 +331,8 @@ def test_plot_bar(close_figures) -> None:
329331

330332

331333
def test_plot_barh(close_figures) -> None:
332-
check(assert_type(IRIS_DF.plot.barh(), plt.Axes), plt.Axes)
333-
check(assert_type(IRIS_DF.plot(kind="barh"), plt.Axes), plt.Axes)
334+
check(assert_type(IRIS_DF.plot.barh(), Axes), Axes)
335+
check(assert_type(IRIS_DF.plot(kind="barh"), Axes), Axes)
334336
check(
335337
assert_type(
336338
IRIS_DF.plot.barh(subplots=True),
@@ -348,8 +350,8 @@ def test_plot_barh(close_figures) -> None:
348350

349351

350352
def test_plot_box(close_figures) -> None:
351-
check(assert_type(IRIS_DF.plot.box(), plt.Axes), plt.Axes)
352-
check(assert_type(IRIS_DF.plot(kind="box"), plt.Axes), plt.Axes)
353+
check(assert_type(IRIS_DF.plot.box(), Axes), Axes)
354+
check(assert_type(IRIS_DF.plot(kind="box"), Axes), Axes)
353355
check(
354356
assert_type(
355357
IRIS_DF.plot.box(subplots=True),
@@ -367,8 +369,8 @@ def test_plot_box(close_figures) -> None:
367369

368370

369371
def test_plot_density(close_figures) -> None:
370-
check(assert_type(IRIS_DF.plot.density(), plt.Axes), plt.Axes)
371-
check(assert_type(IRIS_DF.plot(kind="density"), plt.Axes), plt.Axes)
372+
check(assert_type(IRIS_DF.plot.density(), Axes), Axes)
373+
check(assert_type(IRIS_DF.plot(kind="density"), Axes), Axes)
372374
check(
373375
assert_type(
374376
IRIS_DF.plot.density(subplots=True),
@@ -387,14 +389,12 @@ def test_plot_density(close_figures) -> None:
387389

388390
def test_plot_hexbin(close_figures) -> None:
389391
check(
390-
assert_type(IRIS_DF.plot.hexbin(x="SepalLength", y="SepalWidth"), plt.Axes),
391-
plt.Axes,
392+
assert_type(IRIS_DF.plot.hexbin(x="SepalLength", y="SepalWidth"), Axes),
393+
Axes,
392394
)
393395
check(
394-
assert_type(
395-
IRIS_DF.plot(x="SepalLength", y="SepalWidth", kind="hexbin"), plt.Axes
396-
),
397-
plt.Axes,
396+
assert_type(IRIS_DF.plot(x="SepalLength", y="SepalWidth", kind="hexbin"), Axes),
397+
Axes,
398398
)
399399
check(
400400
assert_type(
@@ -413,8 +413,8 @@ def test_plot_hexbin(close_figures) -> None:
413413

414414

415415
def test_plot_hist(close_figures) -> None:
416-
check(assert_type(IRIS_DF.plot.hist(), plt.Axes), plt.Axes)
417-
check(assert_type(IRIS_DF.plot(kind="hist"), plt.Axes), plt.Axes)
416+
check(assert_type(IRIS_DF.plot.hist(), Axes), Axes)
417+
check(assert_type(IRIS_DF.plot(kind="hist"), Axes), Axes)
418418
check(
419419
assert_type(
420420
IRIS_DF.plot.hist(subplots=True),
@@ -432,8 +432,8 @@ def test_plot_hist(close_figures) -> None:
432432

433433

434434
def test_plot_kde(close_figures) -> None:
435-
check(assert_type(IRIS_DF.plot.kde(), plt.Axes), plt.Axes)
436-
check(assert_type(IRIS_DF.plot(kind="kde"), plt.Axes), plt.Axes)
435+
check(assert_type(IRIS_DF.plot.kde(), Axes), Axes)
436+
check(assert_type(IRIS_DF.plot(kind="kde"), Axes), Axes)
437437
check(
438438
assert_type(
439439
IRIS_DF.plot.kde(subplots=True),
@@ -451,8 +451,8 @@ def test_plot_kde(close_figures) -> None:
451451

452452

453453
def test_plot_pie(close_figures) -> None:
454-
check(assert_type(IRIS_DF.plot.pie(y="SepalLength"), plt.Axes), plt.Axes)
455-
check(assert_type(IRIS_DF.plot(kind="pie", y="SepalLength"), plt.Axes), plt.Axes)
454+
check(assert_type(IRIS_DF.plot.pie(y="SepalLength"), Axes), Axes)
455+
check(assert_type(IRIS_DF.plot(kind="pie", y="SepalLength"), Axes), Axes)
456456
check(
457457
assert_type(
458458
IRIS_DF.plot.pie(y="SepalLength", subplots=True),
@@ -472,14 +472,14 @@ def test_plot_pie(close_figures) -> None:
472472

473473
def test_plot_scatter(close_figures) -> None:
474474
check(
475-
assert_type(IRIS_DF.plot.scatter(x="SepalLength", y="SepalWidth"), plt.Axes),
476-
plt.Axes,
475+
assert_type(IRIS_DF.plot.scatter(x="SepalLength", y="SepalWidth"), Axes),
476+
Axes,
477477
)
478478
check(
479479
assert_type(
480-
IRIS_DF.plot(x="SepalLength", y="SepalWidth", kind="scatter"), plt.Axes
480+
IRIS_DF.plot(x="SepalLength", y="SepalWidth", kind="scatter"), Axes
481481
),
482-
plt.Axes,
482+
Axes,
483483
)
484484
check(
485485
assert_type(
@@ -538,9 +538,9 @@ def test_plot_keywords(close_figures):
538538
include_bool=True,
539539
backend="matplotlib",
540540
),
541-
plt.Axes,
541+
Axes,
542542
),
543-
plt.Axes,
543+
Axes,
544544
)
545545

546546
df = pd.DataFrame(np.random.rand(50, 4), columns=["a", "b", "c", "d"])
@@ -558,17 +558,15 @@ def test_plot_keywords(close_figures):
558558
s=50,
559559
colorbar=False,
560560
),
561-
plt.Axes,
561+
Axes,
562562
),
563-
plt.Axes,
563+
Axes,
564564
)
565565

566566
df = pd.DataFrame(np.random.rand(10, 5), columns=["A", "B", "C", "D", "E"])
567567
check(
568-
assert_type(
569-
df.plot(kind="box", vert=False, positions=[1, 4, 5, 6, 8]), plt.Axes
570-
),
571-
plt.Axes,
568+
assert_type(df.plot(kind="box", vert=False, positions=[1, 4, 5, 6, 8]), Axes),
569+
Axes,
572570
)
573571

574572

0 commit comments

Comments
 (0)