Skip to content

Commit abbae9a

Browse files
author
Marco Gorelli
committed
add series tests
1 parent 01fd802 commit abbae9a

File tree

6 files changed

+313
-425
lines changed

6 files changed

+313
-425
lines changed

doc/source/whatsnew/v1.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Other enhancements
4444
- :class:`Styler` may now render CSS more efficiently where multiple cells have the same styling (:issue:`30876`)
4545
- When writing directly to a sqlite connection :func:`to_sql` now supports the ``multi`` method (:issue:`29921`)
4646
-
47-
- :meth:`Series.info` has been added, for compatibility with :meth:`DataFrame.info`
47+
- :meth:`Series.info` has been added, for compatibility with :meth:`DataFrame.info` (:issue:`5167`)
4848
-
4949

5050
.. ---------------------------------------------------------------------------

pandas/core/frame.py

+90-8
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,7 @@ def to_html(
22232223
encoding=encoding,
22242224
)
22252225

2226+
# ----------------------------------------------------------------------
22262227
@Substitution(
22272228
klass="DataFrame",
22282229
type_sub=" and columns",
@@ -2233,17 +2234,98 @@ def to_html(
22332234
is used. By default, the setting in
22342235
``pandas.options.display.max_info_columns`` is used.
22352236
""",
2237+
examples_sub="""
2238+
>>> int_values = [1, 2, 3, 4, 5]
2239+
>>> text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon']
2240+
>>> float_values = [0.0, 0.25, 0.5, 0.75, 1.0]
2241+
>>> df = pd.DataFrame({"int_col": int_values, "text_col": text_values,
2242+
... "float_col": float_values})
2243+
>>> df
2244+
int_col text_col float_col
2245+
0 1 alpha 0.00
2246+
1 2 beta 0.25
2247+
2 3 gamma 0.50
2248+
3 4 delta 0.75
2249+
4 5 epsilon 1.00
2250+
2251+
Prints information of all columns:
2252+
2253+
>>> df.info(verbose=True)
2254+
<class 'pandas.core.frame.DataFrame'>
2255+
RangeIndex: 5 entries, 0 to 4
2256+
Data columns (total 3 columns):
2257+
# Column Non-Null Count Dtype
2258+
--- ------ -------------- -----
2259+
0 int_col 5 non-null int64
2260+
1 text_col 5 non-null object
2261+
2 float_col 5 non-null float64
2262+
dtypes: float64(1), int64(1), object(1)
2263+
memory usage: 248.0+ bytes
2264+
2265+
Prints a summary of columns count and its dtypes but not per column
2266+
information:
2267+
2268+
>>> df.info(verbose=False)
2269+
<class 'pandas.core.frame.DataFrame'>
2270+
RangeIndex: 5 entries, 0 to 4
2271+
Columns: 3 entries, int_col to float_col
2272+
dtypes: float64(1), int64(1), object(1)
2273+
memory usage: 248.0+ bytes
2274+
2275+
Pipe output of DataFrame.info to buffer instead of sys.stdout, get
2276+
buffer content and writes to a text file:
2277+
2278+
>>> import io
2279+
>>> buffer = io.StringIO()
2280+
>>> df.info(buf=buffer)
2281+
>>> s = buffer.getvalue()
2282+
>>> with open("df_info.txt", "w",
2283+
... encoding="utf-8") as f: # doctest: +SKIP
2284+
... f.write(s)
2285+
260
2286+
The `memory_usage` parameter allows deep introspection mode, specially
2287+
useful for big DataFrames and fine-tune memory optimization:
2288+
>>> random_strings_array = np.random.choice(['a', 'b', 'c'], 10 ** 6)
2289+
>>> df = pd.DataFrame({
2290+
... 'column_1': np.random.choice(['a', 'b', 'c'], 10 ** 6),
2291+
... 'column_2': np.random.choice(['a', 'b', 'c'], 10 ** 6),
2292+
... 'column_3': np.random.choice(['a', 'b', 'c'], 10 ** 6)
2293+
... })
2294+
>>> df.info()
2295+
<class 'pandas.core.frame.DataFrame'>
2296+
RangeIndex: 1000000 entries, 0 to 999999
2297+
Data columns (total 3 columns):
2298+
# Column Non-Null Count Dtype
2299+
--- ------ -------------- -----
2300+
0 column_1 1000000 non-null object
2301+
1 column_2 1000000 non-null object
2302+
2 column_3 1000000 non-null object
2303+
dtypes: object(3)
2304+
memory usage: 22.9+ MB
2305+
>>> df.info(memory_usage='deep')
2306+
<class 'pandas.core.frame.DataFrame'>
2307+
RangeIndex: 1000000 entries, 0 to 999999
2308+
Data columns (total 3 columns):
2309+
# Column Non-Null Count Dtype
2310+
--- ------ -------------- -----
2311+
0 column_1 1000000 non-null object
2312+
1 column_2 1000000 non-null object
2313+
2 column_3 1000000 non-null object
2314+
dtypes: object(3)
2315+
memory usage: 188.8 MB""",
2316+
see_also_sub="""
2317+
DataFrame.describe: Generate descriptive statistics of DataFrame
2318+
columns.
2319+
DataFrame.memory_usage: Memory usage of DataFrame columns.""",
22362320
)
2237-
@Appender(NDFrame.info.__doc__)
2238-
def info(
2239-
self, verbose=None, buf=None, max_cols=None, memory_usage=None, null_counts=None
2240-
):
2241-
return super().info(verbose, buf, max_cols, memory_usage, null_counts)
2242-
2243-
# ----------------------------------------------------------------------
22442321
@Appender(info.__doc__)
22452322
def info(
2246-
self, verbose=None, buf=None, max_cols=None, memory_usage=None, null_counts=None
2323+
self,
2324+
verbose: Optional[bool] = None,
2325+
buf: Optional[IO[str]] = None,
2326+
max_cols: Optional[int] = None,
2327+
memory_usage: Optional[Union[bool, str]] = None,
2328+
null_counts: Optional[bool] = None,
22472329
) -> None:
22482330
return info(self, verbose, buf, max_cols, memory_usage, null_counts)
22492331

0 commit comments

Comments
 (0)