From aa3ac27e1fb6bb9c61cad88e2c0c92b9f4e6b7a7 Mon Sep 17 00:00:00 2001 From: AlexTereshenkov <50622389+AlexTereshenkov@users.noreply.github.com> Date: Wed, 5 Jun 2019 10:24:28 +0100 Subject: [PATCH 1/4] Remove redundant check arr_or_dtype is None Checking whether `if arr_or_dtype is None:` is done in the beginning of the function so the following check is redundant and can be safely removed --- pandas/core/dtypes/common.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index b5cd73a81962b..8e67ef1c14cdf 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1902,8 +1902,6 @@ def _is_dtype_type(arr_or_dtype, condition): if issubclass(arr_or_dtype, ExtensionDtype): arr_or_dtype = arr_or_dtype.type return condition(np.dtype(arr_or_dtype).type) - elif arr_or_dtype is None: - return condition(type(None)) # if we have an array-like if hasattr(arr_or_dtype, 'dtype'): From 44b521d9e932d9e4a57f3837e3a4bd9bf5641bb9 Mon Sep 17 00:00:00 2001 From: AlexTereshenkov <50622389+AlexTereshenkov@users.noreply.github.com> Date: Wed, 5 Jun 2019 12:12:05 +0100 Subject: [PATCH 2/4] Keeping the check under the fastpath block Keeping the check under the fastpath block so all fastpaths are collected. --- pandas/core/dtypes/common.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 8e67ef1c14cdf..24210154a3f16 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1892,9 +1892,6 @@ def _is_dtype_type(arr_or_dtype, condition): bool : if the condition is satisifed for the arr_or_dtype """ - if arr_or_dtype is None: - return condition(type(None)) - # fastpath if isinstance(arr_or_dtype, np.dtype): return condition(arr_or_dtype.type) @@ -1902,7 +1899,9 @@ def _is_dtype_type(arr_or_dtype, condition): if issubclass(arr_or_dtype, ExtensionDtype): arr_or_dtype = arr_or_dtype.type return condition(np.dtype(arr_or_dtype).type) - + elif arr_or_dtype is None: + return condition(type(None)) + # if we have an array-like if hasattr(arr_or_dtype, 'dtype'): arr_or_dtype = arr_or_dtype.dtype From b8f1357388e4eb52bfef3ae0e37fba90502a0787 Mon Sep 17 00:00:00 2001 From: AlexTereshenkov <50622389+AlexTereshenkov@users.noreply.github.com> Date: Wed, 5 Jun 2019 12:14:39 +0100 Subject: [PATCH 3/4] Strip whitespace Strip whitespace --- pandas/core/dtypes/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 24210154a3f16..aa2cc3053ac65 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1901,7 +1901,7 @@ def _is_dtype_type(arr_or_dtype, condition): return condition(np.dtype(arr_or_dtype).type) elif arr_or_dtype is None: return condition(type(None)) - + # if we have an array-like if hasattr(arr_or_dtype, 'dtype'): arr_or_dtype = arr_or_dtype.dtype From 1524eb8acf9665d29ee3cc98208fd3bde6869325 Mon Sep 17 00:00:00 2001 From: AlexTereshenkov <50622389+AlexTereshenkov@users.noreply.github.com> Date: Wed, 5 Jun 2019 13:42:35 +0100 Subject: [PATCH 4/4] Moving the check Moving the check --- pandas/core/dtypes/common.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index aa2cc3053ac65..8e67ef1c14cdf 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1892,6 +1892,9 @@ def _is_dtype_type(arr_or_dtype, condition): bool : if the condition is satisifed for the arr_or_dtype """ + if arr_or_dtype is None: + return condition(type(None)) + # fastpath if isinstance(arr_or_dtype, np.dtype): return condition(arr_or_dtype.type) @@ -1899,8 +1902,6 @@ def _is_dtype_type(arr_or_dtype, condition): if issubclass(arr_or_dtype, ExtensionDtype): arr_or_dtype = arr_or_dtype.type return condition(np.dtype(arr_or_dtype).type) - elif arr_or_dtype is None: - return condition(type(None)) # if we have an array-like if hasattr(arr_or_dtype, 'dtype'):