Skip to content

Pass the errors and kwargs arguments through to astype in the columns… #25888

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 12 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
3 changes: 2 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5716,7 +5716,8 @@ def astype(self, dtype, copy=True, errors='raise', **kwargs):
results = []
for col_name, col in self.iteritems():
if col_name in dtype:
results.append(col.astype(dtype[col_name], copy=copy))
results.append(col.astype(dtype=dtype[col_name], copy=copy,
errors=errors, **kwargs))
else:
results.append(results.append(col.copy() if copy else col))

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ def test_downcast(self):
expected = o.astype(np.int64)
self._compare(result, expected)

def test_multiple_astype_casts(self):
df = DataFrame({'A': [1, 2, 'z'], 'B': [3, 4, 'z']})
df.astype({'A': int,
'B': 'datetime64[ns]'},
errors='ignore')

def test_constructor_compound_dtypes(self):
# see gh-5191
# Compound dtypes should raise NotImplementedError.
Expand Down