Skip to content

Added try-except clause to catch numpy error. #27970

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ def init_dict(data, index, columns, dtype=None):

# no obvious "empty" int column
if missing.any() and not is_integer_dtype(dtype):
if dtype is None or np.issubdtype(dtype, np.flexible):
if is_categorical_dtype(dtype):
Copy link
Member

@mroeschke mroeschke Aug 18, 2019

Choose a reason for hiding this comment

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

Based on the original issue this needs to be is_extension_array_dtype.

nan_dtype = dtype
elif dtype is None or np.issubdtype(dtype, np.flexible):
# GH#1783
nan_dtype = object
else:
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/frame/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def test_empty_frame_dtypes_ftypes(self):
norows_df = pd.DataFrame(columns=list("abc"))
assert_series_equal(norows_df.dtypes, pd.Series(np.object, index=list("abc")))

cat = pd.CategoricalDtype()
Copy link
Member

Choose a reason for hiding this comment

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

Could you add tests for other extension dtypes (e.g. datetime with timezones and/or period)

norows_cat_df = pd.DataFrame(columns=list("abc"), dtype=cat)
assert_series_equal(norows_cat_df.dtypes, pd.Series(cat, index=list("abc")))

# GH 26705 - Assert .ftypes is deprecated
with tm.assert_produces_warning(FutureWarning):
assert_series_equal(
Expand Down