From b895c3c9723de33c3677ab1b75979cb8ccf29309 Mon Sep 17 00:00:00 2001 From: araraonline Date: Wed, 3 Oct 2018 15:38:23 -0300 Subject: [PATCH 01/12] Comment _all_indexes_same --- pandas/core/indexes/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index e50a4b099a8e1..01f5724b30909 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -155,6 +155,8 @@ def _get_consensus_names(indexes): def _all_indexes_same(indexes): + """Determine if all indexes contain the same elements + """ first = indexes[0] for index in indexes[1:]: if not first.equals(index): From 548a428c9ccb411549045460fbc2c4a663bff059 Mon Sep 17 00:00:00 2001 From: araraonline Date: Wed, 3 Oct 2018 15:38:37 -0300 Subject: [PATCH 02/12] Comment _get_consensus_names --- pandas/core/indexes/api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 01f5724b30909..e0fdcb0694efd 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -144,6 +144,11 @@ def _sanitize_and_check(indexes): def _get_consensus_names(indexes): + """Give a consensus 'names' to indexes + + If there's exactly one non-empty 'names', return this, + otherwise, return empty. + """ # find the non-none names, need to tupleify to make # the set hashable, then reverse on return From 43608462c965bbbda7bf7c52795ca16a3da62cd6 Mon Sep 17 00:00:00 2001 From: araraonline Date: Wed, 3 Oct 2018 15:25:49 -0300 Subject: [PATCH 03/12] Comment _sanitize_and_check --- pandas/core/indexes/api.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index e0fdcb0694efd..fe06bfe522578 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -126,6 +126,16 @@ def conv(i): def _sanitize_and_check(indexes): + """Verify the type of indexes and convert lists to Index + + Cases: + + - [list, list, ...]: Return ([list, list, ...], 'list') + - [list, Index, ...]: Return _sanitize_and_check([Index, Index, ...]) + Lists are sorted and converted to Index + - [Index, Index, ...]: Return ([Index, Index, ...], TYPE) + TYPE = 'special' if at least one special type, 'array' otherwise + """ kinds = list({type(index) for index in indexes}) if list in kinds: From ec20c271104fed5ce3f44a4182bf9a945edb8a0d Mon Sep 17 00:00:00 2001 From: araraonline Date: Wed, 3 Oct 2018 15:29:19 -0300 Subject: [PATCH 04/12] Comment _union_indexes --- pandas/core/indexes/api.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index fe06bfe522578..789153048d382 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -77,6 +77,10 @@ def _get_combined_index(indexes, intersect=False, sort=False): def _union_indexes(indexes, sort=True): + """Return the union of indexes + + The behavior of sort and names is not consistent. + """ if len(indexes) == 0: raise AssertionError('Must have at least 1 Index to union') if len(indexes) == 1: From 974fdc3234c32979021f05ed633cd94a81054bcd Mon Sep 17 00:00:00 2001 From: araraonline Date: Wed, 3 Oct 2018 15:30:06 -0300 Subject: [PATCH 05/12] Comment _get_combined_index --- pandas/core/indexes/api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 789153048d382..ce54ae58a0a7a 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -54,6 +54,9 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): def _get_combined_index(indexes, intersect=False, sort=False): + """Return the union or intersection of indexes + """ + # TODO: handle index names! indexes = com.get_distinct_objs(indexes) if len(indexes) == 0: From 76c3e5dd035b8de33e606a73347aa5b1258c9d12 Mon Sep 17 00:00:00 2001 From: araraonline Date: Wed, 3 Oct 2018 15:30:50 -0300 Subject: [PATCH 06/12] Comment _get_objs_combined_axis --- pandas/core/indexes/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index ce54ae58a0a7a..14e1af53c43ec 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -44,9 +44,10 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): - # Extract combined index: return intersection or union (depending on the - # value of "intersect") of indexes on given axis, or None if all objects - # lack indexes (e.g. they are numpy arrays) + """Extract combined index: return intersection or union (depending on the + value of "intersect") of indexes on given axis, or None if all objects + lack indexes (e.g. they are numpy arrays) + """ obs_idxes = [obj._get_axis(axis) for obj in objs if hasattr(obj, '_get_axis')] if obs_idxes: From efb5dc099250603cdf2bb76a31593e1905633633 Mon Sep 17 00:00:00 2001 From: araraonline Date: Wed, 3 Oct 2018 15:55:44 -0300 Subject: [PATCH 07/12] Comment _unique_indices --- pandas/core/indexes/api.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 14e1af53c43ec..e1228de574b26 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -96,6 +96,10 @@ def _union_indexes(indexes, sort=True): indexes, kind = _sanitize_and_check(indexes) def _unique_indices(inds): + """Convert indexes to lists and concatenate them, removing duplicates + + The final dtype is inferred. + """ def conv(i): if isinstance(i, Index): i = i.tolist() From 2e30318dfe2cb689d97e655efad6094b5fac3d45 Mon Sep 17 00:00:00 2001 From: araraonline Date: Thu, 4 Oct 2018 16:46:13 -0300 Subject: [PATCH 08/12] Add Parameters and Returns to docstrings --- pandas/core/indexes/api.py | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index e1228de574b26..b3deee1760450 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -47,6 +47,23 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): """Extract combined index: return intersection or union (depending on the value of "intersect") of indexes on given axis, or None if all objects lack indexes (e.g. they are numpy arrays) + + Parameters + ---------- + objs: list of objects + Each object will only be considered if it has a _get_axis + attribute + intersect: boolean, default False + If True, calculate the intersection between indexes. Otherwise, + calculate the union + axis: {0 or 'index', 1 or 'outer'}, default 0 + The axis to extract indexes from + sort: boolean, default True + Whether the result index should come out sorted or not + + Returns + ------- + Index """ obs_idxes = [obj._get_axis(axis) for obj in objs if hasattr(obj, '_get_axis')] @@ -56,6 +73,20 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): def _get_combined_index(indexes, intersect=False, sort=False): """Return the union or intersection of indexes + + Parameters + ---------- + indexes: a list of Index or list objects + When intersect=True, do not accept list of lists + intersect: boolean, default False + If True, calculate the intersection between indexes. Otherwise, + calculate the union + sort: boolean, default False + Whether the result index should come out sorted or not + + Returns + ------- + Index """ # TODO: handle index names! @@ -84,6 +115,16 @@ def _union_indexes(indexes, sort=True): """Return the union of indexes The behavior of sort and names is not consistent. + + Parameters + ---------- + indexes: a list of Index or list objects + sort: boolean, default True + Whether the result index should come out sorted or not + + Returns + ------- + Index """ if len(indexes) == 0: raise AssertionError('Must have at least 1 Index to union') @@ -99,6 +140,14 @@ def _unique_indices(inds): """Convert indexes to lists and concatenate them, removing duplicates The final dtype is inferred. + + Parameters + ---------- + inds: a list of Index or list objects + + Returns + ------- + Index """ def conv(i): if isinstance(i, Index): @@ -147,6 +196,15 @@ def _sanitize_and_check(indexes): Lists are sorted and converted to Index - [Index, Index, ...]: Return ([Index, Index, ...], TYPE) TYPE = 'special' if at least one special type, 'array' otherwise + + Parameters + ---------- + indexes: a list of Index or list objects + + Returns + ------- + sanitized_indexes: list of Index or list objects + type: {'list', 'array', 'special'} """ kinds = list({type(index) for index in indexes}) @@ -170,6 +228,15 @@ def _get_consensus_names(indexes): If there's exactly one non-empty 'names', return this, otherwise, return empty. + + Parameters + ---------- + indexes: a list of index objects + + Returns + ------- + list + A list representing the consensus 'names' found """ # find the non-none names, need to tupleify to make @@ -183,6 +250,15 @@ def _get_consensus_names(indexes): def _all_indexes_same(indexes): """Determine if all indexes contain the same elements + + Parameters + ---------- + indexes: a list of Index objects + + Returns + ------- + boolean + True if all indexes contain the same elements, False otherwise """ first = indexes[0] for index in indexes[1:]: From 5fb5dd4ab3f8a7a14feb764c89a4a5095de28f4b Mon Sep 17 00:00:00 2001 From: araraonline Date: Tue, 9 Oct 2018 21:31:54 -0300 Subject: [PATCH 09/12] Start content on next line --- pandas/core/indexes/api.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index b3deee1760450..da0f6bd8cc268 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -44,7 +44,8 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): - """Extract combined index: return intersection or union (depending on the + """ + Extract combined index: return intersection or union (depending on the value of "intersect") of indexes on given axis, or None if all objects lack indexes (e.g. they are numpy arrays) @@ -72,7 +73,8 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): def _get_combined_index(indexes, intersect=False, sort=False): - """Return the union or intersection of indexes + """ + Return the union or intersection of indexes Parameters ---------- @@ -112,7 +114,8 @@ def _get_combined_index(indexes, intersect=False, sort=False): def _union_indexes(indexes, sort=True): - """Return the union of indexes + """ + Return the union of indexes The behavior of sort and names is not consistent. @@ -137,7 +140,8 @@ def _union_indexes(indexes, sort=True): indexes, kind = _sanitize_and_check(indexes) def _unique_indices(inds): - """Convert indexes to lists and concatenate them, removing duplicates + """ + Convert indexes to lists and concatenate them, removing duplicates The final dtype is inferred. @@ -187,7 +191,8 @@ def conv(i): def _sanitize_and_check(indexes): - """Verify the type of indexes and convert lists to Index + """ + Verify the type of indexes and convert lists to Index Cases: @@ -224,7 +229,8 @@ def _sanitize_and_check(indexes): def _get_consensus_names(indexes): - """Give a consensus 'names' to indexes + """ + Give a consensus 'names' to indexes If there's exactly one non-empty 'names', return this, otherwise, return empty. @@ -249,7 +255,8 @@ def _get_consensus_names(indexes): def _all_indexes_same(indexes): - """Determine if all indexes contain the same elements + """ + Determine if all indexes contain the same elements Parameters ---------- From e6244955c11c03f1be1be5e68dd9711d72734eda Mon Sep 17 00:00:00 2001 From: araraonline Date: Tue, 9 Oct 2018 21:34:38 -0300 Subject: [PATCH 10/12] Add space after parameter names --- pandas/core/indexes/api.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index da0f6bd8cc268..9186582c3508a 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -51,15 +51,15 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): Parameters ---------- - objs: list of objects + objs : list of objects Each object will only be considered if it has a _get_axis attribute - intersect: boolean, default False + intersect : boolean, default False If True, calculate the intersection between indexes. Otherwise, calculate the union - axis: {0 or 'index', 1 or 'outer'}, default 0 + axis : {0 or 'index', 1 or 'outer'}, default 0 The axis to extract indexes from - sort: boolean, default True + sort : boolean, default True Whether the result index should come out sorted or not Returns @@ -78,12 +78,12 @@ def _get_combined_index(indexes, intersect=False, sort=False): Parameters ---------- - indexes: a list of Index or list objects + indexes : a list of Index or list objects When intersect=True, do not accept list of lists - intersect: boolean, default False + intersect : boolean, default False If True, calculate the intersection between indexes. Otherwise, calculate the union - sort: boolean, default False + sort : boolean, default False Whether the result index should come out sorted or not Returns @@ -121,8 +121,8 @@ def _union_indexes(indexes, sort=True): Parameters ---------- - indexes: a list of Index or list objects - sort: boolean, default True + indexes : a list of Index or list objects + sort : boolean, default True Whether the result index should come out sorted or not Returns @@ -147,7 +147,7 @@ def _unique_indices(inds): Parameters ---------- - inds: a list of Index or list objects + inds : a list of Index or list objects Returns ------- @@ -204,12 +204,12 @@ def _sanitize_and_check(indexes): Parameters ---------- - indexes: a list of Index or list objects + indexes : a list of Index or list objects Returns ------- - sanitized_indexes: list of Index or list objects - type: {'list', 'array', 'special'} + sanitized_indexes : list of Index or list objects + type : {'list', 'array', 'special'} """ kinds = list({type(index) for index in indexes}) @@ -237,7 +237,7 @@ def _get_consensus_names(indexes): Parameters ---------- - indexes: a list of index objects + indexes : a list of index objects Returns ------- @@ -260,7 +260,7 @@ def _all_indexes_same(indexes): Parameters ---------- - indexes: a list of Index objects + indexes : a list of Index objects Returns ------- From 10cb2dd210a7f484139645c79f296cde0678dc2a Mon Sep 17 00:00:00 2001 From: araraonline Date: Tue, 9 Oct 2018 21:41:25 -0300 Subject: [PATCH 11/12] Add missing periods in docstrings --- pandas/core/indexes/api.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 9186582c3508a..b6ef83202cb32 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -47,20 +47,20 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): """ Extract combined index: return intersection or union (depending on the value of "intersect") of indexes on given axis, or None if all objects - lack indexes (e.g. they are numpy arrays) + lack indexes (e.g. they are numpy arrays). Parameters ---------- objs : list of objects Each object will only be considered if it has a _get_axis - attribute + attribute. intersect : boolean, default False If True, calculate the intersection between indexes. Otherwise, - calculate the union + calculate the union. axis : {0 or 'index', 1 or 'outer'}, default 0 - The axis to extract indexes from + The axis to extract indexes from. sort : boolean, default True - Whether the result index should come out sorted or not + Whether the result index should come out sorted or not. Returns ------- @@ -74,17 +74,17 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): def _get_combined_index(indexes, intersect=False, sort=False): """ - Return the union or intersection of indexes + Return the union or intersection of indexes. Parameters ---------- indexes : a list of Index or list objects - When intersect=True, do not accept list of lists + When intersect=True, do not accept list of lists. intersect : boolean, default False If True, calculate the intersection between indexes. Otherwise, - calculate the union + calculate the union. sort : boolean, default False - Whether the result index should come out sorted or not + Whether the result index should come out sorted or not. Returns ------- @@ -115,7 +115,7 @@ def _get_combined_index(indexes, intersect=False, sort=False): def _union_indexes(indexes, sort=True): """ - Return the union of indexes + Return the union of indexes. The behavior of sort and names is not consistent. @@ -123,7 +123,7 @@ def _union_indexes(indexes, sort=True): ---------- indexes : a list of Index or list objects sort : boolean, default True - Whether the result index should come out sorted or not + Whether the result index should come out sorted or not. Returns ------- @@ -141,7 +141,7 @@ def _union_indexes(indexes, sort=True): def _unique_indices(inds): """ - Convert indexes to lists and concatenate them, removing duplicates + Convert indexes to lists and concatenate them, removing duplicates. The final dtype is inferred. @@ -192,15 +192,15 @@ def conv(i): def _sanitize_and_check(indexes): """ - Verify the type of indexes and convert lists to Index + Verify the type of indexes and convert lists to Index. Cases: - [list, list, ...]: Return ([list, list, ...], 'list') - [list, Index, ...]: Return _sanitize_and_check([Index, Index, ...]) - Lists are sorted and converted to Index + Lists are sorted and converted to Index. - [Index, Index, ...]: Return ([Index, Index, ...], TYPE) - TYPE = 'special' if at least one special type, 'array' otherwise + TYPE = 'special' if at least one special type, 'array' otherwise. Parameters ---------- @@ -230,7 +230,7 @@ def _sanitize_and_check(indexes): def _get_consensus_names(indexes): """ - Give a consensus 'names' to indexes + Give a consensus 'names' to indexes. If there's exactly one non-empty 'names', return this, otherwise, return empty. @@ -242,7 +242,7 @@ def _get_consensus_names(indexes): Returns ------- list - A list representing the consensus 'names' found + A list representing the consensus 'names' found. """ # find the non-none names, need to tupleify to make @@ -256,7 +256,7 @@ def _get_consensus_names(indexes): def _all_indexes_same(indexes): """ - Determine if all indexes contain the same elements + Determine if all indexes contain the same elements. Parameters ---------- @@ -265,7 +265,7 @@ def _all_indexes_same(indexes): Returns ------- boolean - True if all indexes contain the same elements, False otherwise + True if all indexes contain the same elements, False otherwise. """ first = indexes[0] for index in indexes[1:]: From 62e7a3ea54fc1eaeb8cb770a6a7ce4a036e52b80 Mon Sep 17 00:00:00 2001 From: araraonline Date: Tue, 9 Oct 2018 21:46:04 -0300 Subject: [PATCH 12/12] Fix parameter types --- pandas/core/indexes/api.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index b6ef83202cb32..4929710d416e7 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -54,12 +54,12 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): objs : list of objects Each object will only be considered if it has a _get_axis attribute. - intersect : boolean, default False + intersect : bool, default False If True, calculate the intersection between indexes. Otherwise, calculate the union. axis : {0 or 'index', 1 or 'outer'}, default 0 The axis to extract indexes from. - sort : boolean, default True + sort : bool, default True Whether the result index should come out sorted or not. Returns @@ -78,12 +78,12 @@ def _get_combined_index(indexes, intersect=False, sort=False): Parameters ---------- - indexes : a list of Index or list objects + indexes : list of Index or list objects When intersect=True, do not accept list of lists. - intersect : boolean, default False + intersect : bool, default False If True, calculate the intersection between indexes. Otherwise, calculate the union. - sort : boolean, default False + sort : bool, default False Whether the result index should come out sorted or not. Returns @@ -121,8 +121,8 @@ def _union_indexes(indexes, sort=True): Parameters ---------- - indexes : a list of Index or list objects - sort : boolean, default True + indexes : list of Index or list objects + sort : bool, default True Whether the result index should come out sorted or not. Returns @@ -147,7 +147,7 @@ def _unique_indices(inds): Parameters ---------- - inds : a list of Index or list objects + inds : list of Index or list objects Returns ------- @@ -204,7 +204,7 @@ def _sanitize_and_check(indexes): Parameters ---------- - indexes : a list of Index or list objects + indexes : list of Index or list objects Returns ------- @@ -237,7 +237,7 @@ def _get_consensus_names(indexes): Parameters ---------- - indexes : a list of index objects + indexes : list of Index objects Returns ------- @@ -260,11 +260,11 @@ def _all_indexes_same(indexes): Parameters ---------- - indexes : a list of Index objects + indexes : list of Index objects Returns ------- - boolean + bool True if all indexes contain the same elements, False otherwise. """ first = indexes[0]