From 1802ae47162817e07f7b6861182964b2a55c22b6 Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:27:58 +0100 Subject: [PATCH 01/20] DOC: Improved docstring of pandas.index.min() --- pandas/core/base.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 280b8849792e3..8ef2e45b40739 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -801,7 +801,28 @@ def argmax(self, axis=None): return nanops.nanargmax(self.values) def min(self): - """ The minimum value of the object """ + """ + Return the minimum value of the Index object. + + Returns + ------- + scalar or object + minimum value + + See Also + -------- + Index.max : Return the maximum value of the object. + + Examples + -------- + >>> idx = pd.Index([3, 2, 1]) + >>> idx.min() + 1 + + >>> idx = pd.Index(['c', 'b', 'a']) + >>> idx.min() + 'a' + """ return nanops.nanmin(self.values) def argmin(self, axis=None): From fdaee80097e8da184f3c8db5cd8488933639d123 Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:33:12 +0100 Subject: [PATCH 02/20] DOC: docstring improved pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 8ef2e45b40739..1b8bd5bcb0a2f 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -816,7 +816,7 @@ def min(self): Examples -------- >>> idx = pd.Index([3, 2, 1]) - >>> idx.min() + >>> idx.min() 1 >>> idx = pd.Index(['c', 'b', 'a']) From c44accdd989b63ba16f47cff3f399cd856948f2f Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:37:58 +0100 Subject: [PATCH 03/20] DOC: improved docstring pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 1b8bd5bcb0a2f..8ef2e45b40739 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -816,7 +816,7 @@ def min(self): Examples -------- >>> idx = pd.Index([3, 2, 1]) - >>> idx.min() + >>> idx.min() 1 >>> idx = pd.Index(['c', 'b', 'a']) From 12cfd8d061ef36dc10173070b3474399a9464e0e Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:46:15 +0100 Subject: [PATCH 04/20] DOC: improved docstring pandas.index.min --- pandas/core/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/base.py b/pandas/core/base.py index 8ef2e45b40739..9dd720757bc0c 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -804,6 +804,9 @@ def min(self): """ Return the minimum value of the Index object. + Return the maximum value of the object within the same type. + Remember you also can access to the index of a DataFrame as pandas.DataFrame.index. + Returns ------- scalar or object From dfd389da9c8da25d3d9ae17d9348b1b2b5545a32 Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:50:21 +0100 Subject: [PATCH 05/20] DOC: improved docstring pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 9dd720757bc0c..270ee617fbbba 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -805,7 +805,7 @@ def min(self): Return the minimum value of the Index object. Return the maximum value of the object within the same type. - Remember you also can access to the index of a DataFrame as pandas.DataFrame.index. + The index of a DataFrame can be also accessed via pandas.DataFrame.index. Returns ------- From 4bc62e61b95e6fef31154539b3515c2359252f58 Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:54:44 +0100 Subject: [PATCH 06/20] DOC: improved docstring pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 270ee617fbbba..a5d88c929dbb2 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -805,7 +805,7 @@ def min(self): Return the minimum value of the Index object. Return the maximum value of the object within the same type. - The index of a DataFrame can be also accessed via pandas.DataFrame.index. + The Index of a DataFrame can be accessed as pandas.DataFrame.index. Returns ------- From 2ce2921a4bd1a260c13bbbd4c056f6d3906f842c Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 15:04:45 +0100 Subject: [PATCH 07/20] DOC: improved docstring pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index a5d88c929dbb2..854e3435e9665 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -804,7 +804,7 @@ def min(self): """ Return the minimum value of the Index object. - Return the maximum value of the object within the same type. + Return the minimum value of the object within the same type. The Index of a DataFrame can be accessed as pandas.DataFrame.index. Returns From e717374845fc046ec3b8e17e690cad42958e1f89 Mon Sep 17 00:00:00 2001 From: Kate Surta Date: Sat, 10 Mar 2018 14:42:52 +0300 Subject: [PATCH 08/20] BUG: Check for wrong arguments in index subclasses constructors (#20017) --- doc/source/whatsnew/v0.23.0.txt | 1 + pandas/core/indexes/category.py | 2 +- pandas/core/indexes/datetimes.py | 16 ++++++------ pandas/core/indexes/interval.py | 4 +-- pandas/core/indexes/multi.py | 4 +-- pandas/core/indexes/period.py | 13 +++++++--- pandas/core/indexes/range.py | 6 ++--- pandas/core/indexes/timedeltas.py | 7 +++--- pandas/tests/indexes/test_base.py | 7 ++++++ pandas/util/testing.py | 41 ++++++++++++++++++++++--------- 10 files changed, 67 insertions(+), 34 deletions(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 3afd9cff10e86..f686a042c1a74 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -935,6 +935,7 @@ Indexing - Bug in :func:`IntervalIndex.symmetric_difference` where the symmetric difference with a non-``IntervalIndex`` did not raise (:issue:`18475`) - Bug in :class:`IntervalIndex` where set operations that returned an empty ``IntervalIndex`` had the wrong dtype (:issue:`19101`) - Bug in :meth:`DataFrame.drop_duplicates` where no ``KeyError`` is raised when passing in columns that don't exist on the ``DataFrame`` (issue:`19726`) +- Bug in ``Index`` subclasses constructors that ignore unexpected keyword arguments (:issue:`19348`) MultiIndex diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index 218851b1713f2..71d39ad812d20 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -76,7 +76,7 @@ class CategoricalIndex(Index, accessor.PandasDelegate): _attributes = ['name'] def __new__(cls, data=None, categories=None, ordered=None, dtype=None, - copy=False, name=None, fastpath=False, **kwargs): + copy=False, name=None, fastpath=False): if fastpath: return cls._simple_new(data, name=name, dtype=dtype) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e5e9bba269fd4..491fefe8efee0 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -213,6 +213,10 @@ class DatetimeIndex(DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin, Attempt to infer fall dst-transition hours based on order name : object Name to be stored in the index + dayfirst : bool, default False + If True, parse dates in `data` with the day first order + yearfirst : bool, default False + If True parse dates in `data` with the year first order Attributes ---------- @@ -272,6 +276,7 @@ class DatetimeIndex(DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin, Index : The base pandas Index type TimedeltaIndex : Index of timedelta64 data PeriodIndex : Index of Period data + pandas.to_datetime : Convert argument to datetime """ _typ = 'datetimeindex' @@ -327,10 +332,10 @@ def _add_comparison_methods(cls): @deprecate_kwarg(old_arg_name='infer_dst', new_arg_name='ambiguous', mapping={True: 'infer', False: 'raise'}) def __new__(cls, data=None, - freq=None, start=None, end=None, periods=None, - copy=False, name=None, tz=None, - verify_integrity=True, normalize=False, - closed=None, ambiguous='raise', dtype=None, **kwargs): + freq=None, start=None, end=None, periods=None, tz=None, + normalize=False, closed=None, ambiguous='raise', + dayfirst=False, yearfirst=False, dtype=None, + copy=False, name=None, verify_integrity=True): # This allows to later ensure that the 'copy' parameter is honored: if isinstance(data, Index): @@ -341,9 +346,6 @@ def __new__(cls, data=None, if name is None and hasattr(data, 'name'): name = data.name - dayfirst = kwargs.pop('dayfirst', None) - yearfirst = kwargs.pop('yearfirst', None) - freq_infer = False if not isinstance(freq, DateOffset): diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index d431ea1e51e31..ccf2e5e3c4486 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -213,8 +213,8 @@ class IntervalIndex(IntervalMixin, Index): _mask = None - def __new__(cls, data, closed=None, name=None, copy=False, dtype=None, - fastpath=False, verify_integrity=True): + def __new__(cls, data, closed=None, dtype=None, copy=False, + name=None, fastpath=False, verify_integrity=True): if fastpath: return cls._simple_new(data.left, data.right, closed, name, diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 73f4aee1c4880..8b6d945854960 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -208,8 +208,8 @@ class MultiIndex(Index): rename = Index.set_names def __new__(cls, levels=None, labels=None, sortorder=None, names=None, - copy=False, verify_integrity=True, _set_identity=True, - name=None, **kwargs): + dtype=None, copy=False, name=None, + verify_integrity=True, _set_identity=True): # compat with Index if name is not None: diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 97cb3fbd877dd..705dc36d92522 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -234,8 +234,15 @@ def _add_comparison_methods(cls): cls.__ge__ = _period_index_cmp('__ge__', cls) def __new__(cls, data=None, ordinal=None, freq=None, start=None, end=None, - periods=None, copy=False, name=None, tz=None, dtype=None, - **kwargs): + periods=None, tz=None, dtype=None, copy=False, name=None, + **fields): + + valid_field_set = {'year', 'month', 'day', 'quarter', + 'hour', 'minute', 'second'} + + if not set(fields).issubset(valid_field_set): + raise TypeError('__new__() got an unexpected keyword argument {}'. + format(list(set(fields) - valid_field_set)[0])) if periods is not None: if is_float(periods): @@ -267,7 +274,7 @@ def __new__(cls, data=None, ordinal=None, freq=None, start=None, end=None, data = np.asarray(ordinal, dtype=np.int64) else: data, freq = cls._generate_range(start, end, periods, - freq, kwargs) + freq, fields) return cls._from_ordinals(data, name=name, freq=freq) if isinstance(data, PeriodIndex): diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index 7c266dc889368..4e192548a1f2d 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -65,8 +65,8 @@ class RangeIndex(Int64Index): _typ = 'rangeindex' _engine_type = libindex.Int64Engine - def __new__(cls, start=None, stop=None, step=None, name=None, dtype=None, - fastpath=False, copy=False, **kwargs): + def __new__(cls, start=None, stop=None, step=None, + dtype=None, copy=False, name=None, fastpath=False): if fastpath: return cls._simple_new(start, stop, step, name=name) @@ -550,7 +550,7 @@ def __getitem__(self, key): stop = self._start + self._step * stop step = self._step * step - return RangeIndex(start, stop, step, self.name, fastpath=True) + return RangeIndex(start, stop, step, name=self.name, fastpath=True) # fall back to Int64Index return super_getitem(key) diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index a14de18b1012f..969afccdbc755 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -197,10 +197,9 @@ def _add_comparison_methods(cls): freq = None - def __new__(cls, data=None, unit=None, - freq=None, start=None, end=None, periods=None, - copy=False, name=None, - closed=None, verify_integrity=True, **kwargs): + def __new__(cls, data=None, unit=None, freq=None, start=None, end=None, + periods=None, closed=None, dtype=None, copy=False, + name=None, verify_integrity=True): if isinstance(data, TimedeltaIndex) and freq is None and name is None: if copy: diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 964a6b14d2b1e..eb429f46a3355 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -2326,3 +2326,10 @@ def test_generated_op_names(opname, indices): opname = '__{name}__'.format(name=opname) method = getattr(index, opname) assert method.__name__ == opname + + +@pytest.mark.parametrize('idx_maker', tm.index_subclass_makers_generator()) +def test_index_subclass_constructor_wrong_kwargs(idx_maker): + # GH #19348 + with tm.assert_raises_regex(TypeError, 'unexpected keyword argument'): + idx_maker(foo='bar') diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 942416408e4f0..a223e4d8fd23e 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1539,16 +1539,16 @@ def makeUnicodeIndex(k=10, name=None): return Index(randu_array(nchars=10, size=k), name=name) -def makeCategoricalIndex(k=10, n=3, name=None): +def makeCategoricalIndex(k=10, n=3, name=None, **kwargs): """ make a length k index or n categories """ x = rands_array(nchars=4, size=n) - return CategoricalIndex(np.random.choice(x, k), name=name) + return CategoricalIndex(np.random.choice(x, k), name=name, **kwargs) -def makeIntervalIndex(k=10, name=None): +def makeIntervalIndex(k=10, name=None, **kwargs): """ make a length k IntervalIndex """ x = np.linspace(0, 100, num=(k + 1)) - return IntervalIndex.from_breaks(x, name=name) + return IntervalIndex.from_breaks(x, name=name, **kwargs) def makeBoolIndex(k=10, name=None): @@ -1567,8 +1567,8 @@ def makeUIntIndex(k=10, name=None): return Index([2**63 + i for i in lrange(k)], name=name) -def makeRangeIndex(k=10, name=None): - return RangeIndex(0, k, 1, name=name) +def makeRangeIndex(k=10, name=None, **kwargs): + return RangeIndex(0, k, 1, name=name, **kwargs) def makeFloatIndex(k=10, name=None): @@ -1576,22 +1576,28 @@ def makeFloatIndex(k=10, name=None): return Index(values * (10 ** np.random.randint(0, 9)), name=name) -def makeDateIndex(k=10, freq='B', name=None): +def makeDateIndex(k=10, freq='B', name=None, **kwargs): dt = datetime(2000, 1, 1) dr = bdate_range(dt, periods=k, freq=freq, name=name) - return DatetimeIndex(dr, name=name) + return DatetimeIndex(dr, name=name, **kwargs) -def makeTimedeltaIndex(k=10, freq='D', name=None): - return TimedeltaIndex(start='1 day', periods=k, freq=freq, name=name) +def makeTimedeltaIndex(k=10, freq='D', name=None, **kwargs): + return TimedeltaIndex(start='1 day', periods=k, freq=freq, + name=name, **kwargs) -def makePeriodIndex(k=10, name=None): +def makePeriodIndex(k=10, name=None, **kwargs): dt = datetime(2000, 1, 1) - dr = PeriodIndex(start=dt, periods=k, freq='B', name=name) + dr = PeriodIndex(start=dt, periods=k, freq='B', name=name, **kwargs) return dr +def makeMultiIndex(k=10, names=None, **kwargs): + return MultiIndex.from_product( + (('foo', 'bar'), (1, 2)), names=names, **kwargs) + + def all_index_generator(k=10): """Generator which can be iterated over to get instances of all the various index classes. @@ -1609,6 +1615,17 @@ def all_index_generator(k=10): yield make_index_func(k=k) +def index_subclass_makers_generator(): + make_index_funcs = [ + makeDateIndex, makePeriodIndex, + makeTimedeltaIndex, makeRangeIndex, + makeIntervalIndex, makeCategoricalIndex, + makeMultiIndex + ] + for make_index_func in make_index_funcs: + yield make_index_func + + def all_timeseries_index_generator(k=10): """Generator which can be iterated over to get instances of all the classes which represent time-seires. From 49a6e084681d0830fc8bc5028e23121254c927bc Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Sat, 10 Mar 2018 06:54:19 -0500 Subject: [PATCH 09/20] DOC: lint --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 7e6ae88a26e7c..52283e4e223b4 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1156,7 +1156,7 @@ def to_frame(self, index=True): >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() animal - animal + animal Ant Ant Bear Bear Cow Cow From 4e8e93706769527ffbf33e720df7ecbdff8d1e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Contest=C3=AD?= <25779507+jcontesti@users.noreply.github.com> Date: Sat, 10 Mar 2018 13:24:35 +0100 Subject: [PATCH 10/20] DOC: Improved the docstring of Series.str.findall (#19982) --- pandas/core/strings.py | 85 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 7 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 6b427ed1da834..fac607f4621a8 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -898,23 +898,94 @@ def str_join(arr, sep): def str_findall(arr, pat, flags=0): """ - Find all occurrences of pattern or regular expression in the - Series/Index. Equivalent to :func:`re.findall`. + Find all occurrences of pattern or regular expression in the Series/Index. + + Equivalent to applying :func:`re.findall` to all the elements in the + Series/Index. Parameters ---------- pat : string - Pattern or regular expression - flags : int, default 0 (no flags) - re module flags, e.g. re.IGNORECASE + Pattern or regular expression. + flags : int, default 0 + ``re`` module flags, e.g. `re.IGNORECASE` (default is 0, which means + no flags). Returns ------- - matches : Series/Index of lists + Series/Index of lists of strings + All non-overlapping matches of pattern or regular expression in each + string of this Series/Index. See Also -------- - extractall : returns DataFrame with one column per capture group + count : Count occurrences of pattern or regular expression in each string + of the Series/Index. + extractall : For each string in the Series, extract groups from all matches + of regular expression and return a DataFrame with one row for each + match and one column for each group. + re.findall : The equivalent ``re`` function to all non-overlapping matches + of pattern or regular expression in string, as a list of strings. + + Examples + -------- + + >>> s = pd.Series(['Lion', 'Monkey', 'Rabbit']) + + The search for the pattern 'Monkey' returns one match: + + >>> s.str.findall('Monkey') + 0 [] + 1 [Monkey] + 2 [] + dtype: object + + On the other hand, the search for the pattern 'MONKEY' doesn't return any + match: + + >>> s.str.findall('MONKEY') + 0 [] + 1 [] + 2 [] + dtype: object + + Flags can be added to the pattern or regular expression. For instance, + to find the pattern 'MONKEY' ignoring the case: + + >>> import re + >>> s.str.findall('MONKEY', flags=re.IGNORECASE) + 0 [] + 1 [Monkey] + 2 [] + dtype: object + + When the pattern matches more than one string in the Series, all matches + are returned: + + >>> s.str.findall('on') + 0 [on] + 1 [on] + 2 [] + dtype: object + + Regular expressions are supported too. For instance, the search for all the + strings ending with the word 'on' is shown next: + + >>> s.str.findall('on$') + 0 [on] + 1 [] + 2 [] + dtype: object + + If the pattern is found more than once in the same string, then a list of + multiple strings is returned: + + >>> s.str.findall('b') + 0 [] + 1 [] + 2 [b, b] + dtype: object + """ regex = re.compile(pat, flags=flags) return _na_map(regex.findall, arr) From b437afd678b9d576398353f5c189235fff9d88ac Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:33:12 +0100 Subject: [PATCH 11/20] DOC: docstring improved pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 8ef2e45b40739..1b8bd5bcb0a2f 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -816,7 +816,7 @@ def min(self): Examples -------- >>> idx = pd.Index([3, 2, 1]) - >>> idx.min() + >>> idx.min() 1 >>> idx = pd.Index(['c', 'b', 'a']) From d3b33983eea9d6ed5d92807d7054f3202f899e15 Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:33:12 +0100 Subject: [PATCH 12/20] DOC: improved docstring pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 1b8bd5bcb0a2f..800bb16e2f22f 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -806,7 +806,7 @@ def min(self): Returns ------- - scalar or object + Scalar or object. minimum value See Also From 9bf1cae659ad8883f2a3f43729e76781686f27f3 Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:46:15 +0100 Subject: [PATCH 13/20] DOC: improved docstring pandas.index.min --- pandas/core/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/base.py b/pandas/core/base.py index 800bb16e2f22f..364be5086666a 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -804,6 +804,9 @@ def min(self): """ Return the minimum value of the Index object. + Return the maximum value of the object within the same type. + Remember you also can access to the index of a DataFrame as pandas.DataFrame.index. + Returns ------- Scalar or object. From fe581bafe5553ce943b957585c75e7866ebac065 Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:50:21 +0100 Subject: [PATCH 14/20] DOC: improved docstring pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 364be5086666a..d6a68869db53c 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -805,7 +805,7 @@ def min(self): Return the minimum value of the Index object. Return the maximum value of the object within the same type. - Remember you also can access to the index of a DataFrame as pandas.DataFrame.index. + The index of a DataFrame can be also accessed via pandas.DataFrame.index. Returns ------- From b5fc47bf33f7136b084365f9454f18cdd29d0d4b Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 14:54:44 +0100 Subject: [PATCH 15/20] DOC: improved docstring pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index d6a68869db53c..aab42494a9101 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -805,7 +805,7 @@ def min(self): Return the minimum value of the Index object. Return the maximum value of the object within the same type. - The index of a DataFrame can be also accessed via pandas.DataFrame.index. + The Index of a DataFrame can be accessed as pandas.DataFrame.index. Returns ------- From 4ea435119cac7b912eac4e848094d1bdb7649330 Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 15:04:45 +0100 Subject: [PATCH 16/20] DOC: improved docstring pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index aab42494a9101..dbdb509bb4489 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -804,7 +804,7 @@ def min(self): """ Return the minimum value of the Index object. - Return the maximum value of the object within the same type. + Return the minimum value of the object within the same type. The Index of a DataFrame can be accessed as pandas.DataFrame.index. Returns From 5c00e65f90603febbe045e63ba65cf3f8934f21d Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 15:35:27 +0100 Subject: [PATCH 17/20] DOC:improved docstring pandas.index.min --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index dbdb509bb4489..5d34c7a15dd22 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -819,7 +819,7 @@ def min(self): Examples -------- >>> idx = pd.Index([3, 2, 1]) - >>> idx.min() + >>> idx.min() 1 >>> idx = pd.Index(['c', 'b', 'a']) From c7887cc1d21170303ce8ebcd394b3ed643768df6 Mon Sep 17 00:00:00 2001 From: juan huguet Date: Sat, 10 Mar 2018 15:39:02 +0100 Subject: [PATCH 18/20] DOC:improved docstring pandas.index.min --- pandas/core/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 5d34c7a15dd22..f5bedccd2d586 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -809,8 +809,8 @@ def min(self): Returns ------- - Scalar or object. - minimum value + scalar or object + Minimum value. See Also -------- From 4896e0b483e28f3b12cab5268c4aa1de9deb5e59 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Fri, 16 Mar 2018 16:14:53 -0500 Subject: [PATCH 19/20] Updated [ci skip] [ci skip] --- pandas/core/base.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index f5bedccd2d586..7b700fa0134b5 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -802,19 +802,18 @@ def argmax(self, axis=None): def min(self): """ - Return the minimum value of the Index object. - - Return the minimum value of the object within the same type. - The Index of a DataFrame can be accessed as pandas.DataFrame.index. + Return the minimum value of the Index. Returns ------- - scalar or object + scalar Minimum value. See Also -------- Index.max : Return the maximum value of the object. + Series.max : Return the maximum value in a Series. + DataFrame.max : Return the maximum values in a DataFrame. Examples -------- @@ -825,6 +824,11 @@ def min(self): >>> idx = pd.Index(['c', 'b', 'a']) >>> idx.min() 'a' + + For a MultiIndex, the minimum is determined lexicographically. + >>> idx = pd.MultiIndex.from_product([('a', 'b'), (2, 1)]) + >>> idx.min() + ('a', 1) """ return nanops.nanmin(self.values) From 7d65b9e9b68b9962fc8a21e47725b739a97264a5 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Fri, 16 Mar 2018 16:15:37 -0500 Subject: [PATCH 20/20] Fixup [ci skip] [ci skip] --- pandas/core/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 7b700fa0134b5..fc6550d45b0c3 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -812,8 +812,8 @@ def min(self): See Also -------- Index.max : Return the maximum value of the object. - Series.max : Return the maximum value in a Series. - DataFrame.max : Return the maximum values in a DataFrame. + Series.min : Return the minimum value in a Series. + DataFrame.min : Return the minimum values in a DataFrame. Examples --------