From 02abbdb842fd51b19e2c16dd4618100e8e293486 Mon Sep 17 00:00:00 2001 From: Askhat Nuriddinov Date: Fri, 23 Feb 2024 21:30:16 +0300 Subject: [PATCH] Added types to df.info() (#875) Co-authored-by: Askhat Nuriddinov --- pandas-stubs/core/frame.pyi | 7 ++++++- tests/test_frame.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 7da14910..fe3fef2f 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -570,7 +570,12 @@ class DataFrame(NDFrame, OpsMixin): storage_options: StorageOptions = ..., ) -> str: ... def info( - self, verbose=..., buf=..., max_cols=..., memory_usage=..., null_counts=... + self, + verbose: bool | None = ..., + buf: WriteBuffer[str] = ..., + max_cols: int | None = ..., + memory_usage: bool | Literal["deep"] | None = ..., + show_counts: bool | None = ..., ) -> None: ... def memory_usage(self, index: _bool = ..., deep: _bool = ...) -> Series: ... def transpose(self, *args, copy: _bool = ...) -> DataFrame: ... diff --git a/tests/test_frame.py b/tests/test_frame.py index 93c72656..0eab8191 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -3147,3 +3147,25 @@ def test_get() -> None: pd.DataFrame, ) check(assert_type(df.get(["z"], default=1), Union[pd.DataFrame, int]), int) + + +def test_info() -> None: + df = pd.DataFrame() + + check(assert_type(df.info(verbose=True), None), type(None)) + check(assert_type(df.info(verbose=False), None), type(None)) + check(assert_type(df.info(verbose=None), None), type(None)) + + check(assert_type(df.info(buf=io.StringIO()), None), type(None)) + + check(assert_type(df.info(max_cols=1), None), type(None)) + check(assert_type(df.info(max_cols=None), None), type(None)) + + check(assert_type(df.info(memory_usage=True), None), type(None)) + check(assert_type(df.info(memory_usage=False), None), type(None)) + check(assert_type(df.info(memory_usage="deep"), None), type(None)) + check(assert_type(df.info(memory_usage=None), None), type(None)) + + check(assert_type(df.info(show_counts=True), None), type(None)) + check(assert_type(df.info(show_counts=False), None), type(None)) + check(assert_type(df.info(show_counts=None), None), type(None))