From 1cb6323a42f2c6af64a8ab073db952401ffc9cfc Mon Sep 17 00:00:00 2001 From: Dan King Date: Mon, 28 Aug 2023 12:08:11 -0400 Subject: [PATCH] [query] MT.tail should prefer `n_rows` to `n`. CHANGELOG: The `n` parameter of `MatrixTable.tail` is deprecated in favor of a new `n_rows` parameter. MT.head already does this. --- hail/python/hail/matrixtable.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/hail/python/hail/matrixtable.py b/hail/python/hail/matrixtable.py index 496293897bfd..a9c98c143046 100644 --- a/hail/python/hail/matrixtable.py +++ b/hail/python/hail/matrixtable.py @@ -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 @@ -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: