pynvl
General purpose data utilities, inspired by PL/SQL.
This package contains a suite of functions which flatten out data handling operations.
🔹 Features
nvl(expr, default)
=> Substitute a value whenNone
is encountereddecode(expr, search1, result1, ..., default)
=> if-elif-else functionalitysign(n)
=> Returns a value indicating the sign of a numbernoneif(expr1, expr2)
=> If expr1 and expr2 are equal then return Nonenvl2(expr, value_if_not_null, value_if_null)
=> Extending NVL to substitute when non-None value is encountereddecode(None, None, ...)
treatsNone == None
(follows PL/SQL)coalesce(expr1, expr2, ..., expr_n)
=> Returns first non-None value in list- Fully tested with
pytest
- MIT Licensed
🔹 Pandas Integration
pynvl
also provides optional pandas-native helpers for use with pd.Series
and operates element-wise.
import pandas as pd
from pynvl import pd_sign, pd_nvl, pd_nvl2, pd_noneif, pd_decode
s = pd.Series([-5, 0, 3, None])
print(pd_sign(s).tolist())
# [-1, 0, 1, None]
print(pd_nvl(s, 99).tolist())
# [-5, 0, 3, 99]
print(pd_nvl2(s, "not-null", "is-null").tolist())
# ['not-null', 'not-null', 'not-null', 'is-null']
print(pd_noneif(s, 0).tolist())
# [-5, None, 3, None]
print(pd_decode(s, -5, "neg", 0, "zero", 3, "pos", default="other").tolist())
# ['neg', 'zero', 'pos', 'other']
🔹 Installation From PyPI
pip install pynvl-lib