Skip to content
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

Check index_dtype and data_dtypes more strictly. #2100

Merged
merged 2 commits into from
Mar 16, 2021
Merged
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
12 changes: 8 additions & 4 deletions databricks/koalas/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,15 @@ def __init__(

index_dtypes = [
spark_type_to_pandas_dtype(spark_frame.select(scol).schema[0].dataType)
if dtype is None
if dtype is None or dtype == np.dtype("object")
else dtype
for dtype, scol in zip(index_dtypes, index_spark_columns)
]

assert all(
as_spark_type(dtype, raise_error=False) is not None for dtype in index_dtypes
isinstance(dtype, Dtype.__args__) # type: ignore
and (dtype == np.dtype("object") or as_spark_type(dtype, raise_error=False) is not None)
for dtype in index_dtypes
), index_dtypes

self._index_dtypes = index_dtypes
Expand Down Expand Up @@ -593,13 +595,15 @@ def __init__(

data_dtypes = [
spark_type_to_pandas_dtype(spark_frame.select(scol).schema[0].dataType)
if dtype is None
if dtype is None or dtype == np.dtype("object")
else dtype
for dtype, scol in zip(data_dtypes, data_spark_columns)
]

assert all(
as_spark_type(dtype, raise_error=False) is not None for dtype in data_dtypes
isinstance(dtype, Dtype.__args__) # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Can I take it as pandas dtype consists of np.dtype and ExtensionDtype?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thanks!

and (dtype == np.dtype("object") or as_spark_type(dtype, raise_error=False) is not None)
for dtype in data_dtypes
), data_dtypes

self._data_dtypes = data_dtypes
Expand Down