Skip to content

Commit b92cf71

Browse files
committed
fix #874 : implemented Axis.min() and Axis.max() methods
1 parent 390b85e commit b92cf71

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

doc/source/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Searching
4949
Axis.startingwith
5050
Axis.endingwith
5151
Axis.matching
52+
Axis.min
53+
Axis.max
5254

5355
Modifying/Selecting
5456
-------------------

doc/source/changes/version_0_33.rst.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Miscellaneous improvements
6363

6464
* implemented the :py:obj:`Array.allclose()` method (closes :issue:`871`).
6565

66+
* implemented :py:obj:`Axis.min()` and :py:obj:`Axis.max()` methods (closes :issue:`874`).
67+
6668
Fixes
6769
^^^^^
6870

larray/core/axis.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import warnings
55
from itertools import product
66

7-
from typing import Union
7+
from typing import Union, Any
88

99
import numpy as np
1010
import pandas as pd
@@ -614,6 +614,60 @@ def equals(self, other):
614614
return isinstance(other, Axis) and self.name == other.name and self.iswildcard == other.iswildcard and \
615615
(len(self) == len(other) if self.iswildcard else np.array_equal(self.labels, other.labels))
616616

617+
def min(self) -> Any:
618+
"""
619+
Get minimum of labels.
620+
621+
Returns
622+
-------
623+
label
624+
Label with minimum value.
625+
626+
Warnings
627+
--------
628+
Fails on non-numeric labels.
629+
630+
Examples
631+
--------
632+
>>> time = Axis('time=1991..2020')
633+
>>> time.min()
634+
1991
635+
636+
>>> country = Axis('country=Belgium,France,Germany')
637+
>>> country.min()
638+
Traceback (most recent call last):
639+
...
640+
TypeError: cannot perform reduce with flexible type
641+
"""
642+
return np.nanmin(self.labels)
643+
644+
def max(self) -> Any:
645+
"""
646+
Get maximum of labels.
647+
648+
Returns
649+
-------
650+
label
651+
Label with maximum value.
652+
653+
Warnings
654+
--------
655+
Fails on non-numeric labels.
656+
657+
Examples
658+
--------
659+
>>> time = Axis('time=1991..2020')
660+
>>> time.max()
661+
2020
662+
663+
>>> country = Axis('country=Belgium,France,Germany')
664+
>>> country.max()
665+
Traceback (most recent call last):
666+
...
667+
TypeError: cannot perform reduce with flexible type
668+
"""
669+
return np.nanmax(self.labels)
670+
617671
def matching(self, deprecated=None, pattern=None, regex=None):
618672
r"""
619673
Returns a group with all the labels matching the specified pattern or regular expression.

0 commit comments

Comments
 (0)