@@ -53,9 +53,9 @@ def __getitem__(self, label):
5353 def __setitem__ (self , label , values ):
5454 if not isinstance (values , np .ndarray ):
5555 # Coerce a single value to a sequence
56- if isinstance ( values , str ) or not isinstance (values , collections . abc . Sequence ):
56+ if not _is_non_string_iterable (values ):
5757 values = [values ] * max (self .num_rows , 1 )
58- values = np .array (values )
58+ values = np .array (tuple ( values ) )
5959 if hasattr (self , '_num_rows' ) & self .num_rows > 0 :
6060 assert len (values ) == self .num_rows , 'column length mismatch'
6161 else :
@@ -689,15 +689,15 @@ def _fill_with_zeroes(order, rows, zero=None):
689689 assert len (rows ) > 0
690690 index = dict (rows )
691691 if zero is None :
692- array = np .array (list (index .values ()))
692+ array = np .array (tuple (index .values ()))
693693 if len (array .shape ) == 1 :
694694 zero = array .dtype .type ()
695695 return np .array ([index .get (k , zero ) for k in order ])
696696
697697
698698def _as_labels (column_label_or_labels ):
699699 """Return a list of labels for a label or labels."""
700- if not isinstance (column_label_or_labels , collections . abc . Sequence ):
700+ if not _is_non_string_iterable (column_label_or_labels ):
701701 return [column_label_or_labels ]
702702 else :
703703 return column_label_or_labels
@@ -718,3 +718,14 @@ def _collected_label(collect, label):
718718 return label + ' ' + collect .__name__
719719 else :
720720 return label
721+
722+
723+ def _is_non_string_iterable (value ):
724+ """Whether a value is iterable."""
725+ if isinstance (value , str ):
726+ return False
727+ if hasattr (value , '__iter__' ):
728+ return True
729+ if isinstance (value , collections .abc .Sequence ):
730+ return True
731+ return False
0 commit comments