@@ -1957,7 +1957,7 @@ def _get_series_list(self, others, ignore_index=False):
1957
1957
# once str.cat defaults to alignment, this function can be simplified;
1958
1958
# will not need `ignore_index` and the second boolean output anymore
1959
1959
1960
- from pandas import Index , Series , DataFrame
1960
+ from pandas import Index , Series , DataFrame , isnull
1961
1961
1962
1962
# self._orig is either Series or Index
1963
1963
idx = self ._orig if isinstance (self ._orig , Index ) else self ._orig .index
@@ -1994,15 +1994,19 @@ def _get_series_list(self, others, ignore_index=False):
1994
1994
fut_warn = False
1995
1995
while others :
1996
1996
nxt = others .pop (0 )
1997
- # safety for iterators etc.; exclude indexed objects
1998
- if ( is_list_like ( nxt ) and
1999
- not isinstance (nxt , (DataFrame , Series , Index ) )):
1997
+ # safety for iterators etc.; nxt is list-like as per above
1998
+ # do not map indexed objects, which would lose their index
1999
+ if not isinstance (nxt , (DataFrame , Series , Index )):
2000
2000
nxt = list (nxt )
2001
2001
2002
- # nested list-likes are forbidden - content must be strings
2003
- is_legal = (is_list_like (nxt ) and
2004
- all (isinstance (x , compat .string_types )
2005
- for x in nxt ))
2002
+ # Nested list-likes are forbidden - content of nxt must be
2003
+ # strings/NaN/None. Need to robustify check against
2004
+ # x in nxt being list-like (otherwise ambiguous boolean).
2005
+ is_legal = all ((isinstance (x , compat .string_types )
2006
+ or (is_list_like (x ) and any (isnull (x )))
2007
+ or (not is_list_like (x ) and isnull (x ))
2008
+ or x is None )
2009
+ for x in nxt )
2006
2010
# DataFrame is false positive of is_legal
2007
2011
# because "x in df" returns column names
2008
2012
if isinstance (nxt , DataFrame ) or not is_legal :
@@ -2012,11 +2016,11 @@ def _get_series_list(self, others, ignore_index=False):
2012
2016
los = los + tmp [0 ]
2013
2017
fut_warn = fut_warn or tmp [1 ]
2014
2018
return (los , fut_warn )
2015
- # test if there is a mix of list-like and string/NaN/None
2019
+ # test if there is a mix of list-like and non-list-like (e.g. str)
2016
2020
elif (any (is_list_like (x ) for x in others )
2017
2021
and any (not is_list_like (x ) for x in others )):
2018
2022
raise TypeError (err_msg )
2019
- else :
2023
+ else : # all elements in others are _not_ list-like
2020
2024
return ([Series (others , index = idx )], False )
2021
2025
raise TypeError (err_msg )
2022
2026
0 commit comments