Skip to content
Merged
Changes from 1 commit
Commits
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
DOC: Improved the docstring of dtypes/ftypes
  • Loading branch information
jongwony committed Mar 11, 2018
commit 05306dbc61234e923e24734db7b9e9eddf8a064d
47 changes: 34 additions & 13 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4278,17 +4278,25 @@ def dtypes(self):
"""
Return the dtypes in this object.
Copy link
Contributor

Choose a reason for hiding this comment

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

Explain in more depth to a novice user that this is used to get the dtypes per column of the DataFrame.


Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a Returns section as specified in the guide?

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a 'See Also' section to contemplate common dtypes.

Notes
-----
It returns a Series with the data type of each column.
This returns a Series with the data type of each column.
The result's index is original DataFrame's columns.
If object contains data multiple dtypes in a single column,
dtypes will be chosen to accommodate all of the data types.
``object`` is the most general.
Copy link
Contributor

Choose a reason for hiding this comment

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

It is worth explaining that str will be represented as object.


Copy link
Contributor

Choose a reason for hiding this comment

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

I believe in a See Also section ftypes could be mentioned.

Returns
-------
pandas.Series
The data type of each column.

See Also
--------
pandas.DataFrame.ftypes

Examples
--------
>>> df = pd.DataFrame({'f': pd.np.random.rand(3),
... 'i': 1,
>>> df = pd.DataFrame({'f': [1.0],
... 'i': [1],
... 'd': pd.Timestamp('20180310'),
... 'o': 'foo'})
Copy link
Contributor

Choose a reason for hiding this comment

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

add in See Also to Series.dtype

>>> df.dtypes
Expand All @@ -4305,21 +4313,34 @@ def dtypes(self):
@property
def ftypes(self):
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

It would better organized it there was pull request for dtypes and another pull request for ftypes.

Return the ftypes (indication of sparse/dense and dtype)
in this object.
Return the ftypes (indication of sparse/dense and dtype) in this object.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a return section.

Notes
-----
Sparse data should have the same dtypes as its dense representation
This returns a Series with the data type of each column.
The result's index is original DataFrame's columns.
If object contains data multiple dtypes in a single column,
dtypes will be chosen to accommodate all of the data types.
``object`` is the most general.
All of the standard pandas data structures have a to_sparse method.
The result's tracks where data has been "sparsified".

Returns
-------
pandas.Series
The data type and indication of sparse/dense of each column.

See Also
Copy link
Contributor

Choose a reason for hiding this comment

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

'See Also' should go before notes.

--------
dtypes, SparseDataFrame
pandas.DataFrame.dtypes, pandas.SparseDataFrame

Notes
-----
Sparse data should have the same dtypes as its dense representation.

Examples
--------
>>> arr = pd.np.random.randn(100, 4)
>>> arr[arr < .8] = pd.np.nan
>>> import numpy as np
>>> arr = np.random.RandomState(0).randn(100, 4)
>>> arr[arr < .8] = np.nan
>>> pd.DataFrame(arr).ftypes
0 float64:dense
1 float64:dense
Expand Down