Skip to content

Commit

Permalink
[query] MT.tail should prefer n_rows to n.
Browse files Browse the repository at this point in the history
CHANGELOG: The `n` parameter of `MatrixTable.tail` is deprecated in favor of a new `n_rows` parameter.

MT.head already does this.
  • Loading branch information
Dan King committed Aug 28, 2023
1 parent f5755b8 commit 1cb6323
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions hail/python/hail/matrixtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4047,8 +4047,8 @@ def head(self, n_rows: Optional[int], n_cols: Optional[int] = None, *, n: Option
mt = MatrixTable(ir.MatrixColsHead(mt._mir, n_cols))
return mt

@typecheck_method(n=nullable(int), n_cols=nullable(int))
def tail(self, n: Optional[int], n_cols: Optional[int] = None) -> 'MatrixTable':
@typecheck_method(n_rows=nullable(int), n_cols=nullable(int), n=nullable(int))
def tail(self, n_rows: Optional[int], n_cols: Optional[int] = None, *, n: Optional[int] = None) -> 'MatrixTable':
"""Subset matrix to last `n` rows.
Examples
Expand Down Expand Up @@ -4087,20 +4087,31 @@ def tail(self, n: Optional[int], n_cols: Optional[int] = None) -> 'MatrixTable':
Parameters
----------
n : :obj:`int`
n_rows : :obj:`int`
Number of rows to include (all rows included if ``None``).
n_cols : :obj:`int`, optional
Number of cols to include (all cols included if ``None``).
n : :obj:`int`
Deprecated in favor of n_rows.
Returns
-------
:class:`.MatrixTable`
Matrix including the last `n` rows and last `n_cols` cols.
"""
if n_rows is not None and n is not None:
raise ValueError('Both n and n_rows specified. Only one may be specified.')

if n_rows is not None:
n_rows_name = 'n_rows'
else:
n_rows = n
n_rows_name = 'n'

mt = self
if n is not None:
if n < 0:
raise ValueError(f"MatrixTable.tail: expect 'n' to be non-negative or None, found '{n}'")
raise ValueError(f"MatrixTable.tail: expect '{n_rows_name}' to be non-negative or None, found '{n}'")
mt = MatrixTable(ir.MatrixRowsTail(mt._mir, n))
if n_cols is not None:
if n_cols < 0:
Expand Down

0 comments on commit 1cb6323

Please sign in to comment.