Skip to content

Commit 0801953

Browse files
taytzehaotzehaoo
andauthored
bug fix 54251 (#54388)
* bug fix 54251 * format * whatsnew format * PR comment fix --------- Co-authored-by: tzehaoo <tzehao@intnt.ai>
1 parent a15711d commit 0801953

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

doc/source/whatsnew/v2.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ Conversion
675675
- Bug in :meth:`DataFrame.info` raising ``ValueError`` when ``use_numba`` is set (:issue:`51922`)
676676
- Bug in :meth:`DataFrame.insert` raising ``TypeError`` if ``loc`` is ``np.int64`` (:issue:`53193`)
677677
- Bug in :meth:`HDFStore.select` loses precision of large int when stored and retrieved (:issue:`54186`)
678+
- Bug in :meth:`Series.astype` not supporting ``object_`` (:issue:`54251`)
678679

679680
Strings
680681
^^^^^^^

pandas/core/dtypes/common.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,13 @@ def pandas_dtype(dtype) -> DtypeObj:
16341634
# also catch some valid dtypes such as object, np.object_ and 'object'
16351635
# which we safeguard against by catching them earlier and returning
16361636
# np.dtype(valid_dtype) before this condition is evaluated.
1637-
if is_hashable(dtype) and dtype in [object, np.object_, "object", "O"]:
1637+
if is_hashable(dtype) and dtype in [
1638+
object,
1639+
np.object_,
1640+
"object",
1641+
"O",
1642+
"object_",
1643+
]:
16381644
# check hashability to avoid errors/DeprecationWarning when we get
16391645
# here and `dtype` is an array
16401646
return npdtype

pandas/tests/dtypes/test_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def test_invalid_dtype_error(self, box):
5353
np.float64,
5454
float,
5555
np.dtype("float64"),
56+
"object_",
5657
],
5758
)
5859
def test_pandas_dtype_valid(self, dtype):

0 commit comments

Comments
 (0)