Skip to content

Commit 5ed92d9

Browse files
committed
Add **kwargs back into astype method
1 parent 99dc246 commit 5ed92d9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pandas/core/generic.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -5776,7 +5776,7 @@ def _to_dict_of_blocks(self, copy=True):
57765776
for k, v, in self._data.to_dict(copy=copy).items()
57775777
}
57785778

5779-
def astype(self, dtype, copy=True, errors="raise"):
5779+
def astype(self, dtype, copy=True, errors="raise", **kwargs):
57805780
"""
57815781
Cast a pandas object to a specified dtype ``dtype``.
57825782
@@ -5799,6 +5799,8 @@ def astype(self, dtype, copy=True, errors="raise"):
57995799
58005800
.. versionadded:: 0.20.0
58015801
5802+
**kwargs : keyword arguments to pass on to the constructor
5803+
58025804
Returns
58035805
-------
58045806
casted : same type as caller
@@ -5884,7 +5886,7 @@ def astype(self, dtype, copy=True, errors="raise"):
58845886
"the key in Series dtype mappings."
58855887
)
58865888
new_type = dtype[self.name]
5887-
return self.astype(new_type, copy, errors)
5889+
return self.astype(new_type, copy, errors, **kwargs)
58885890

58895891
for col_name in dtype.keys():
58905892
if col_name not in self:
@@ -5896,7 +5898,9 @@ def astype(self, dtype, copy=True, errors="raise"):
58965898
for col_name, col in self.items():
58975899
if col_name in dtype:
58985900
results.append(
5899-
col.astype(dtype=dtype[col_name], copy=copy, errors=errors)
5901+
col.astype(
5902+
dtype=dtype[col_name], copy=copy, errors=errors, **kwargs
5903+
)
59005904
)
59015905
else:
59025906
results.append(results.append(col.copy() if copy else col))
@@ -5911,7 +5915,9 @@ def astype(self, dtype, copy=True, errors="raise"):
59115915

59125916
else:
59135917
# else, only a single dtype is given
5914-
new_data = self._data.astype(dtype=dtype, copy=copy, errors=errors)
5918+
new_data = self._data.astype(
5919+
dtype=dtype, copy=copy, errors=errors, **kwargs
5920+
)
59155921
return self._constructor(new_data).__finalize__(self)
59165922

59175923
# GH 19920: retain column metadata after concat

0 commit comments

Comments
 (0)