Skip to content

ENH: enable Series.info() #37320

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

Merged
merged 34 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a903f32
TST: add series info tests
ivanovmg Oct 7, 2020
e07d6e2
TST: remove test that series has no info
ivanovmg Oct 7, 2020
0990d54
ENH: add method Series.info
ivanovmg Oct 7, 2020
1814795
REF: split tests for frame and series
ivanovmg Oct 7, 2020
4c390a8
REF: param test on frame memory_usage_qualified
ivanovmg Oct 7, 2020
81929e6
Merge branch 'master' into feature/series-info
ivanovmg Oct 21, 2020
824d8d6
ENH: enable series info
ivanovmg Oct 21, 2020
ce68e94
CLN: remove extra parens
ivanovmg Oct 21, 2020
ede6dc4
REF: split series-related tests
ivanovmg Oct 23, 2020
789e03e
DOC: add release note
ivanovmg Oct 23, 2020
f41596d
CLN: merge two lines
ivanovmg Oct 23, 2020
40b71f8
DOC: unify series/frame docstrings, fix indent
ivanovmg Oct 23, 2020
3e71336
REF: to_buffer -> render, unify func signature
ivanovmg Oct 23, 2020
739c62d
Merge branch 'master' into feature/series-info
ivanovmg Oct 23, 2020
e9c5220
DOC: add versionadded tag
ivanovmg Oct 23, 2020
f7cb4f8
Merge branch 'master' into feature/series-info
ivanovmg Nov 4, 2020
def5ed6
Merge branch 'master' into feature/series-info
ivanovmg Nov 5, 2020
dd4205d
Merge branch 'master' into feature/series-info
ivanovmg Nov 7, 2020
e74cdce
DOC: maybe fix empty line problem with df.info
ivanovmg Nov 7, 2020
d41ecf1
DOC: remove trailing period in type
ivanovmg Nov 7, 2020
98d0f55
Merge branch 'master' into feature/series-info
ivanovmg Nov 12, 2020
0d1c5d8
Merge branch 'master' into feature/series-info
ivanovmg Oct 4, 2021
816803e
Fix styling
ivanovmg Oct 4, 2021
9e0198f
Merge branch 'master' into feature/series-info
ivanovmg Nov 29, 2021
1e2aaef
DOC: move whatsnew info to v1.4.0
ivanovmg Nov 29, 2021
688080b
DOC: move docs on Series.info() to io/formats/info.py
ivanovmg Nov 29, 2021
4e87b1a
FIX: newline
ivanovmg Nov 29, 2021
dc999fe
FIX: change versionadded to 1.4.0
ivanovmg Nov 29, 2021
4bb4e40
DOC: extract null_counts_sub for frames only
ivanovmg Nov 29, 2021
f114293
DOC: avoid duplication of kwargs replacement
ivanovmg Nov 29, 2021
16ac96e
DOC: unify newlines/spacing with substitutions
ivanovmg Nov 29, 2021
aac2954
Revert "DOC: unify newlines/spacing with substitutions"
ivanovmg Nov 29, 2021
22303dc
DOC: fix newlines substitutions
ivanovmg Nov 29, 2021
9428a32
DOC: another attempt to fix newline
ivanovmg Nov 30, 2021
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
Prev Previous commit
Next Next commit
REF: to_buffer -> render, unify func signature
  • Loading branch information
ivanovmg committed Oct 23, 2020
commit 3e71336b361a65e05e3fe5f01445bc9366fefbea
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ def to_html(
DataFrame.memory_usage: Memory usage of DataFrame columns."""
),
)
@doc(BaseInfo.to_buffer)
@doc(BaseInfo.render)
def info(
self,
verbose: Optional[bool] = None,
Expand All @@ -2627,7 +2627,7 @@ def info(
data=self,
memory_usage=memory_usage,
)
info.to_buffer(
info.render(
buf=buf,
max_cols=max_cols,
verbose=verbose,
Expand Down
10 changes: 3 additions & 7 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4640,7 +4640,7 @@ def replace(
Series.memory_usage: Memory usage of Series."""
),
)
@doc(BaseInfo.to_buffer)
@doc(BaseInfo.render)
def info(
self,
verbose: Optional[bool] = None,
Expand All @@ -4649,13 +4649,9 @@ def info(
memory_usage: Optional[Union[bool, str]] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the docstring for DataFrame.info is

memory_usage: bool, str, optional

I think this should be

memory_usage: bool or 'deep', optional

might be able to use Literal here (see #37137) and maybe create an alias in typing . follow-on OK too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use Literal, but looks like that is available only starting from Python 3.8.

null_counts: bool = True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per #36805 and #37999 , this should be show_counts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but one thing at a time. Will wait for the public API update first.

) -> None:
if max_cols is not None:
raise ValueError(
"Argument `max_cols` can only be passed "
"in DataFrame.info, not Series.info"
)
return SeriesInfo(self, memory_usage).to_buffer(
return SeriesInfo(self, memory_usage).render(
buf=buf,
max_cols=max_cols,
verbose=verbose,
show_counts=null_counts,
)
Expand Down
21 changes: 16 additions & 5 deletions pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ def size_qualifier(self) -> str:
return size_qualifier

@abstractmethod
def to_buffer():
def render(
self,
*,
buf: Optional[IO[str]],
max_cols: Optional[int],
verbose: Optional[bool],
show_counts: Optional[bool],
) -> None:
"""
Print a concise summary of a %(klass)s.

Expand Down Expand Up @@ -266,7 +273,7 @@ def memory_usage_bytes(self) -> int:
deep = False
return self.data.memory_usage(index=True, deep=deep).sum()

def to_buffer(
def render(
self,
*,
buf: Optional[IO[str]],
Expand Down Expand Up @@ -296,15 +303,19 @@ def __init__(
self.data: "Series" = data
self.memory_usage = _initialize_memory_usage(memory_usage)

def to_buffer(
def render(
self,
*,
buf: Optional[IO[str]],
max_cols: Optional[int],
verbose: Optional[bool],
show_counts: Optional[bool],
) -> None:
"""
"""
if max_cols is not None:
raise ValueError(
"Argument `max_cols` can only be passed "
"in DataFrame.info, not Series.info"
)
printer = SeriesInfoPrinter(
info=self,
verbose=verbose,
Expand Down