From ea35874b9713964bbce6f494af2eb777d5386746 Mon Sep 17 00:00:00 2001 From: Punchy Date: Thu, 2 Aug 2018 19:36:21 +0100 Subject: [PATCH 1/8] Clarify return value for str.join --- pandas/core/strings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 6349af4d2e0ac..8d6180805b298 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1105,6 +1105,7 @@ def str_join(arr, sep): Returns ------- Series/Index: object + The list entries concatenated by intervening occurrences of the delimiter. Notes ----- From 5920d157d8ae7e329bf8df4c123dc706d774c85e Mon Sep 17 00:00:00 2001 From: Punchy Date: Thu, 2 Aug 2018 20:26:57 +0100 Subject: [PATCH 2/8] Correction for PEP8 style --- pandas/core/strings.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 8d6180805b298..fb8273e678a67 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1105,7 +1105,8 @@ def str_join(arr, sep): Returns ------- Series/Index: object - The list entries concatenated by intervening occurrences of the delimiter. + The list entries concatenated by intervening occurrences of the + delimiter. Notes ----- @@ -1139,11 +1140,10 @@ def str_join(arr, sep): than str will become a NaN. >>> s.str.join('-') - 0 lion-elephant-zebra - 1 NaN - 2 NaN - 3 NaN - 4 NaN + 0 l-i-o-n + 1 NaN + 2 NaN + 3 swan-fish dtype: object """ return _na_map(sep.join, arr) From 33bf98a5279e67b9b05e21b7bec6c59aa1276b87 Mon Sep 17 00:00:00 2001 From: Punchy Date: Thu, 2 Aug 2018 20:27:28 +0100 Subject: [PATCH 3/8] Fix validation error with list indices --- pandas/core/strings.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index fb8273e678a67..769a6d54f2450 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1123,17 +1123,12 @@ def str_join(arr, sep): Example with a list that contains non-string elements. - >>> s = pd.Series([['lion', 'elephant', 'zebra'], - ... [1.1, 2.2, 3.3], - ... ['cat', np.nan, 'dog'], - ... ['cow', 4.5, 'goat'] - ... ['duck', ['swan', 'fish'], 'guppy']]) + >>> s = pd.Series(['lion', 1.1, np.nan, ['swan', 'fish']]) >>> s - 0 [lion, elephant, zebra] - 1 [1.1, 2.2, 3.3] - 2 [cat, nan, dog] - 3 [cow, 4.5, goat] - 4 [duck, [swan, fish], guppy] + 0 lion + 1 1.1 + 2 NaN + 3 [swan, fish] dtype: object Join all lists using an '-', the lists containing object(s) of types other From 639c090b28779a349261754ad0ea2782b1b89f83 Mon Sep 17 00:00:00 2001 From: Punchy Date: Thu, 2 Aug 2018 20:41:19 +0100 Subject: [PATCH 4/8] Update notes accordingly --- pandas/core/strings.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 769a6d54f2450..51b597e425a60 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1110,9 +1110,12 @@ def str_join(arr, sep): Notes ----- - If any of the lists does not contain string objects the result of the join + If any of the list items is not a string object, the result of the join will be `NaN`. + If the list does not contain string objects, performing a join will raise + an AttributeError. + See Also -------- str.join : Standard library version of this method. @@ -1130,10 +1133,6 @@ def str_join(arr, sep): 2 NaN 3 [swan, fish] dtype: object - - Join all lists using an '-', the lists containing object(s) of types other - than str will become a NaN. - >>> s.str.join('-') 0 l-i-o-n 1 NaN From b78a24abb43a2f1d09c16fc33f142da607eb279f Mon Sep 17 00:00:00 2001 From: Punchy Date: Thu, 2 Aug 2018 21:04:41 +0100 Subject: [PATCH 5/8] Reinstate the previous example - missing comma --- pandas/core/strings.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 51b597e425a60..2367e3748f12f 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1113,7 +1113,7 @@ def str_join(arr, sep): If any of the list items is not a string object, the result of the join will be `NaN`. - If the list does not contain string objects, performing a join will raise + If the Series does not contain string objects, performing a join will raise an AttributeError. See Also @@ -1126,18 +1126,24 @@ def str_join(arr, sep): Example with a list that contains non-string elements. - >>> s = pd.Series(['lion', 1.1, np.nan, ['swan', 'fish']]) + >>> s = pd.Series([['lion', 'elephant', 'zebra'], + ... [1.1, 2.2, 3.3], + ... ['cat', np.nan, 'dog'], + ... ['cow', 4.5, 'goat'], + ... ['duck', ['swan', 'fish'], 'guppy']]) >>> s - 0 lion - 1 1.1 - 2 NaN - 3 [swan, fish] + 0 [lion, elephant, zebra] + 1 [1.1, 2.2, 3.3] + 2 [cat, nan, dog] + 3 [cow, 4.5, goat] + 4 [duck, [swan, fish], guppy] dtype: object >>> s.str.join('-') - 0 l-i-o-n - 1 NaN - 2 NaN - 3 swan-fish + 0 lion-elephant-zebra + 1 NaN + 2 NaN + 3 NaN + 4 NaN dtype: object """ return _na_map(sep.join, arr) From 68308cb792ec99594fe9c3a07cb9640305d21cdb Mon Sep 17 00:00:00 2001 From: Punchy Date: Thu, 2 Aug 2018 23:58:05 +0100 Subject: [PATCH 6/8] Correct indentation --- pandas/core/strings.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 2367e3748f12f..2cb1b4edb844a 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1127,10 +1127,10 @@ def str_join(arr, sep): Example with a list that contains non-string elements. >>> s = pd.Series([['lion', 'elephant', 'zebra'], - ... [1.1, 2.2, 3.3], - ... ['cat', np.nan, 'dog'], - ... ['cow', 4.5, 'goat'], - ... ['duck', ['swan', 'fish'], 'guppy']]) + ... [1.1, 2.2, 3.3], + ... ['cat', np.nan, 'dog'], + ... ['cow', 4.5, 'goat'], + ... ['duck', ['swan', 'fish'], 'guppy']]) >>> s 0 [lion, elephant, zebra] 1 [1.1, 2.2, 3.3] From 35d50e4673b0c28d8fdb8436b92fbff54fd4082f Mon Sep 17 00:00:00 2001 From: Punchy Date: Fri, 3 Aug 2018 00:11:37 +0100 Subject: [PATCH 7/8] Reinstate sentence, with language improvements --- pandas/core/strings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 2cb1b4edb844a..aa70bad54bee0 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1123,7 +1123,6 @@ def str_join(arr, sep): Examples -------- - Example with a list that contains non-string elements. >>> s = pd.Series([['lion', 'elephant', 'zebra'], @@ -1138,6 +1137,10 @@ def str_join(arr, sep): 3 [cow, 4.5, goat] 4 [duck, [swan, fish], guppy] dtype: object + + Join all lists using a '-'. The lists containing object(s) of types other + than str will produce a NaN. + >>> s.str.join('-') 0 lion-elephant-zebra 1 NaN From e03704dec93c5cbd2ac80750e3a6445b63922093 Mon Sep 17 00:00:00 2001 From: Punchy Date: Tue, 7 Aug 2018 18:24:19 +0100 Subject: [PATCH 8/8] Move item from Notes to Raises --- pandas/core/strings.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index aa70bad54bee0..7f630e3a3d8a4 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1108,14 +1108,16 @@ def str_join(arr, sep): The list entries concatenated by intervening occurrences of the delimiter. + Raises + ------- + AttributeError + If the supplied Series contains neither strings nor lists. + Notes ----- If any of the list items is not a string object, the result of the join will be `NaN`. - If the Series does not contain string objects, performing a join will raise - an AttributeError. - See Also -------- str.join : Standard library version of this method.