From dc562f503ffa77e9b34b07852ef46f4e6b21e05a Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Fri, 29 Jul 2022 15:52:11 +0800 Subject: [PATCH] docs(core/utils): update docstrings for `NA` Signed-off-by: Xuehai Pan --- README.md | 16 +++++++++++----- nvitop/core/utils.py | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 27c603d..fc665b2 100644 --- a/README.md +++ b/README.md @@ -997,17 +997,23 @@ Out[18]: MemoryInfo(total=268435456, free=257622016, used=10813440) >>> from nvitop import NA >>> NA 'N/A' + >>> 'memory usage: {}'.format(NA) # NA is an instance of `str` 'memory usage: N/A' ->>> NA + 'str' +>>> NA.lower() # NA is an instance of `str` +'n/a' +>>> NA.ljust(5) # NA is an instance of `str` +'N/A ' +>>> NA + 'str' # string contamination if the operand is a string 'N/Astr' ->>> float(NA) # explicit conversion to float (`math.nan`) + +>>> float(NA) # explicit conversion to float (`math.nan`) nan ->>> NA + 1 # auto-casting to float +>>> NA + 1 # auto-casting to float if the operand is a number nan ->>> NA * 1024 # auto-casting to float +>>> NA * 1024 # auto-casting to float if the operand is a number nan ->>> NA / (1024 * 1024) # auto-casting to float +>>> NA / (1024 * 1024) # auto-casting to float if the operand is a number nan ``` diff --git a/nvitop/core/utils.py b/nvitop/core/utils.py index 3f568fc..a03605a 100644 --- a/nvitop/core/utils.py +++ b/nvitop/core/utils.py @@ -108,17 +108,23 @@ class NaType(str): >>> NA 'N/A' + >>> 'memory usage: {}'.format(NA) # NA is an instance of `str` 'memory usage: N/A' - >>> NA + 'str' + >>> NA.lower() # NA is an instance of `str` + 'n/a' + >>> NA.ljust(5) # NA is an instance of `str` + 'N/A ' + >>> NA + 'str' # string contamination if the operand is a string 'N/Astr' - >>> float(NA) # explicit conversion to float (`math.nan`) + + >>> float(NA) # explicit conversion to float (`math.nan`) nan - >>> NA + 1 # auto-casting to float + >>> NA + 1 # auto-casting to float if the operand is a number nan - >>> NA * 1024 # auto-casting to float + >>> NA * 1024 # auto-casting to float if the operand is a number nan - >>> NA / (1024 * 1024) # auto-casting to float + >>> NA / (1024 * 1024) # auto-casting to float if the operand is a number nan """