Skip to main content

Checks for all kinds of nan/None values without raising Exceptions all the time

from check_if_nan import is_nan,sort_nan_non_nan
import numpy as np
import pandas as pd
import math
a = None
b = pd.NA
c = np.nan
d = math.nan
e = float("nan")
f = []
g = np.array([])
h = dict()
i = tuple()
j = set()
k = ""
l = "NaN"
m = b""
n = bytearray()


print("a", is_nan(a))
print("b", is_nan(b))
print("c", is_nan(c))
print("d", is_nan(d))
print("e", is_nan(e))
print("f", is_nan(f))
print("g", is_nan(g))
print("h", is_nan(h))
print("i", is_nan(i))
print("j", is_nan(j))
print("k", is_nan(k))
print("l", is_nan(l))
print("m", is_nan(m))
print("n", is_nan(n))

print("f", is_nan(f, emptyiters=True))
print("g", is_nan(g, emptyiters=True))
print("h", is_nan(h, emptyiters=True))
print("i", is_nan(i, emptyiters=True))
print("j", is_nan(j, emptyiters=True))
print("k", is_nan(k, emptystrings=True))
print("l", is_nan(l, nastrings=True))
print("m", is_nan(m, emptybytes=True))
print("n", is_nan(n, emptyiters=True))


a True
b True
c True
d True
e True
f False
g False
h False
i False
j False
k False
l False
m False
n False


f True
g True
h True
i True
j True
k True
l True
m True
n True


sor = sort_nan_non_nan(
    seq=[a, b, c, d, e, f, g, h, i, j, k, l, m, n],
    emptyiters=False,
    nastrings=False,
    emptystrings=False,
    emptybytes=False,
)
print(sor)
# defaultdict(<class 'list'>, {True: [(0, None), (1, <NA>), (2, nan),
# (3, nan), (4, nan)], False: [(5, []), (6, array([], dtype=float64)),
# (7, {}), (8, ()), (9, set()), (10, ''), (11, 'NaN'), (12, b''),
# (13, bytearray(b''))]})

sor = sort_nan_non_nan(
    seq=[a, b, c, d, e, f, g, h, i, j, k, l, m, n],
    emptyiters=True,
    nastrings=False,
    emptystrings=False,
    emptybytes=False,
)
print(sor)
# defaultdict(<class 'list'>, {True: [(0, None), (1, <NA>), (2, nan),
# (3, nan), (4, nan), (5, []), (6, array([], dtype=float64)),
# (7, {}), (8, ()), (9, set()), (13, bytearray(b''))],
# False: [(10, ''), (11, 'NaN'), (12, b'')]})


sor = sort_nan_non_nan(
    seq=[a, b, c, d, e, f, g, h, i, j, k, l, m, n],
    emptyiters=True,
    nastrings=False,
    emptystrings=True,
    emptybytes=True,
)
print(sor)
# defaultdict(<class 'list'>, {True: [(0, None), (1, <NA>), (2, nan), (3, nan),
# (4, nan), (5, []), (6, array([], dtype=float64)), (7, {}), (8, ()),
# (9, set()), (10, ''), (12, b''), (13, bytearray(b''))], False: [(11, 'NaN')]})

sor = sort_nan_non_nan(
    seq=[a, b, c, d, e, f, g, h, i, j, k, l, m, n],
    emptyiters=True,
    nastrings=True,
    emptystrings=True,
    emptybytes=True,
)
print(sor)
# defaultdict(<class 'list'>, {True: [(0, None), (1, <NA>), (2, nan),
# (3, nan), (4, nan), (5, []), (6, array([], dtype=float64)), (7, {}),
# (8, ()), (9, set()), (10, ''), (11, 'NaN'), (12, b''), (13, bytearray(b''))]})

Metadata

Release files for check-if-nan 0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for check-if-nan 0.11
File Size Uploaded
check_if_nan-0.11.tar.gz 22.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for check-if-nan 0.11
File Interpreter ABI Platform
check_if_nan-0.11-py3-none-any.whl Python 3 none any Details

Total release size: 44.6 kB

Release files / check_if_nan-0.11.tar.gz

Download URL check_if_nan-0.11.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bf047164e3a24fd17c37d01576d10627d371da6780979dcfe27148a7f01e1d06
BLAKE2b-256 checksum
How to use checksums
65d3a1324cb74dc9c8999800eddecaac9953e612a6185cf657867bbd4ce47bef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / check_if_nan-0.11-py3-none-any.whl

Download URL check_if_nan-0.11-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92b33427fb19c1535a2fb455e54073bf488c928b21a490e28ab65f3ade5aa3c0
BLAKE2b-256 checksum
How to use checksums
4b7131681f3c0d25e578018216984c2405a0301e36aa76350179e15e35613ad2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release history Release notifications | RSS feed

This release

0.11 This release

2 release files

0.10

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page