From 803caae45d1462bf3629dfa3ce51241ce3fa4e72 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 11 Oct 2020 00:23:53 +0200 Subject: [PATCH 1/4] test get value from array --- pandas/core/internals/blocks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 8346b48539887..ce2bc4b76041b 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -943,7 +943,7 @@ def setitem(self, indexer, value): values = values.T # length checking - check_setitem_lengths(indexer, value, values) + check_setitem_lengths(indexer, value[0], values) exact_match = ( len(arr_value.shape) and arr_value.shape[0] == values.shape[0] From 00e4fb2bd399f3ab013b90e3071ec01391d04def Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 11 Oct 2020 01:10:34 +0200 Subject: [PATCH 2/4] check if len is 1 --- pandas/core/indexing.py | 3 +++ pandas/core/internals/blocks.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index a49c0741b64fe..15b4ae2d8db57 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1785,6 +1785,9 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): else: # set the item, possibly having a dtype change ser = ser.copy() + if is_list_like(value): + if len(value) == 1: + value = value[0] ser._mgr = ser._mgr.setitem(indexer=pi, value=value) ser._maybe_update_cacher(clear=True) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index ce2bc4b76041b..28bb4b394ef0c 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -932,7 +932,7 @@ def setitem(self, indexer, value): # value must be storable at this moment if is_extension_array_dtype(getattr(value, "dtype", None)): # We need to be careful not to allow through strings that - # can be parsed to EADtypes + # can be parsed to EADtypes is_ea_value = True arr_value = value else: @@ -943,7 +943,7 @@ def setitem(self, indexer, value): values = values.T # length checking - check_setitem_lengths(indexer, value[0], values) + check_setitem_lengths(indexer, value, values) exact_match = ( len(arr_value.shape) and arr_value.shape[0] == values.shape[0] From 835069498ed856a0d9e505846b39c733105ce14d Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 12 Oct 2020 17:56:20 +0200 Subject: [PATCH 3/4] revert blocks --- pandas/core/internals/blocks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 28bb4b394ef0c..8346b48539887 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -932,7 +932,7 @@ def setitem(self, indexer, value): # value must be storable at this moment if is_extension_array_dtype(getattr(value, "dtype", None)): # We need to be careful not to allow through strings that - # can be parsed to EADtypes + # can be parsed to EADtypes is_ea_value = True arr_value = value else: From 6fd847fc632a6068b4066b2d446f715ba6aae752 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 12 Oct 2020 19:26:45 +0200 Subject: [PATCH 4/4] check for categorical --- pandas/core/indexing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 15b4ae2d8db57..11fb17062bdba 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -21,6 +21,7 @@ is_object_dtype, is_scalar, is_sequence, + is_categorical_dtype ) from pandas.core.dtypes.concat import concat_compat from pandas.core.dtypes.generic import ABCDataFrame, ABCMultiIndex, ABCSeries @@ -1785,9 +1786,8 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): else: # set the item, possibly having a dtype change ser = ser.copy() - if is_list_like(value): - if len(value) == 1: - value = value[0] + # if is_list_like(value) and len(value) == 1 and not is_categorical_dtype(value): + # value = value[0] ser._mgr = ser._mgr.setitem(indexer=pi, value=value) ser._maybe_update_cacher(clear=True)