-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: astype now takes dict mapping col names to datatypes (#14761) #14837
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
DOC: astype now takes dict mapping col names to datatypes (#14761) #14837
Conversation
…v#14761 Updating documentation to reflect change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-charlton Thanks for working on this!
I added a few comments (which I now see you already asked about this in the issue, but only see it now)
@@ -1755,12 +1755,14 @@ then the more *general* one will be used as the result of the operation. | |||
# conversion of dtypes | |||
df3.astype('float32').dtypes | |||
|
|||
.. versionadded:: 0.20.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.20 -> 0.19
and I would also clarify what was added in 0.20.0 (only the ability to specify different dtypes for different columns with a dict)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused. I tried using a dict with column/dtype mapping as an
argument to astype and this works in 0.19.0:
>>> import numpy as np
>>> import pandas as pd
>>> pd.__version__
'0.19.0'
>>> dft = pd.DataFrame({'a': [1,0,1], 'b': [4,5,6], 'c': [7, 8, 9]})
>>> dft = dft.astype({'a': np.bool, 'c': np.uint8})
>>> dft
a b c
0 True 4 7
1 False 5 8
2 True 6 9
>>> dft.dtypes
a bool
b int64
c uint8
dtype: object
I think I'm missing what new functionality has been introduced in v0.20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-charlton As I said above, this feature was already introduced in 0.19.0. That's the reason I asked to change 0.20.0 to 0.19.0 in the versionadded here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Will submit changes today.
Convert a subset of columns to a specified type using :meth:`~DataFrame.astype` | ||
|
||
.. ipython:: python | ||
|
||
dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]}) | ||
dft[['a','b']] = dft[['a','b']].astype(np.uint8) | ||
dft = dft.astype({'a': np.float64, 'c': np.uint8}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave the previous example there as well, and add this line (the single dtype is still a valid case)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I would leave this example, but just add a new one below this one, also beginning with an explaining sentence, like "Convert certain columns to as specific dtype by passing a dict to astype: ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will make relevant changes and resubmit. Old example will be left in place as is.
dft = dft.astype({'a': np.float64, 'c': np.uint8}) | ||
dft | ||
dft.dtypes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-charlton This is not needed, as this enhancement was already added in 0.19.0, and is mentioned in the whatsnew of 0.19.0 (see the changes in the PR https://github.com/pandas-dev/pandas/pull/13375/files)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will leave this file unchanged.
Current coverage is 84.64% (diff: 100%)@@ master #14837 diff @@
==========================================
Files 144 144
Lines 51016 51016
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 43185 43184 -1
- Misses 7831 7832 +1
Partials 0 0
|
@m-charlton you don't need to close this PR or remove the branch on github to update this. You can just push to the same branch, and the PR on github will automatically be updated. |
DataFrame.astype now allows changing the dtype of a column by passing a dict mapping column name to dtype.
DataFrame.astype now allows setting the type of columns by passing a dict mapping column to dtype.
…com/m-charlton/pandas into update_docs_astype_with_dict_#14761
@m-charlton Some git help, seems something went wrong with updating to master. If you do the following, it should normally be solved:
|
I performed the above before I saw your git help. |
Mistakenly added changes carried out in v0.19 to v0.20
Ability to pass dict mapping column to dtype introduced in v0.19 not v0.20
5f6db38
to
b9414a9
Compare
I think I've rectified my mistakes in update b9414a9 |
lgtm. ping on green. |
I think it was more to do with the content so @jorisvandenbossche needs to |
…#14761) (pandas-dev#14837) Document feature which was already added in 0.19..0
git diff upstream/master | flake8 --diff
Updating documentation to reflect change