Each of the three detrending techniques (polynomial, smoothed priors, and SG) can yield negative RR intervals, which is obviously problematic. Here's some code to demonstrate the problem:
from hrv.rri import RRi
from hrv.detrend import smoothness_priors, polynomial_detrend, sg_detrend
rri_vals = [ 795, 832, 827, 897, 916, 902, 870, 827, 819, 757, 749, 725,
727, 743, 725, 722, 719, 773, 784, 832, 908, 897, 859, 835,
859, 824, 805, 754, 760, 765, 711, 849, 528, 762, 671, 725,
1309, 560, 962, 892, 876, 900, 838, 873, 784, 830, 584, 579,
803, 611, 620, 703, 768, 795, 765, 644, 714, 722, 717, 706,
754, 714, 695, 730, 708, 722, 760, 849, 867, 878, 859, 857,
881, 892, 819, 789, 835, 876, 770, 838, 862, 884, 876, 840,
760, 822, 892, 935, 932, 824, 830, 795, 792, 873, 916, 983,
1013, 989, 962, 959, 937, 959, 908, 897, 889, 816, 768, 752,
741, 692, 620, 789, 611, 671, 663, 501, 797, 1517, 708, 601,
894, 708, 730, 711, 733, 717, 719, 711, 671, 636, 641, 649,
595, 636, 620, 628, 703, 725, 808, 792, 851, 867, 881, 927,
894, 884, 873, 892, 916, 862, 870, 908, 967, 964, 943, 851,
822, 843, 916, 989, 1010, 1010, 878, 797, 913, 784, 884, 951,
1018, 1088, 1037, 1029, 929, 876, 805, 738, 706, 652, 655, 692,
665, 606, 676, 673, 679, 757, 725, 1983, 2207, 671, 687, 932,
590, 776, 838, 784, 808, 795, 808, 690, 819, 746, 795, 835,
981, 929, 956, 916, 865, 851, 770, 735, 768, 706, 762, 698,
727, 773, 795, 854, 994, 935, 889, 814, 733, 717, 725, 1072,
1018, 784, 660, 784, 620, 770, 743, 768, 811, 897, 892, 840,
811, 827, 816, 884, 886, 876, 752, 851, 859, 789, 768, 760,
800, 811, 921, 851, 819, 859, 865, 787, 849, 876, 827, 773,
717, 760, 762, 854, 897, 997, 991, 919, 886, 843, 784, 757,
760, 735, 730, 1355, 620, 614, 665, 676, 668, 644, 668, 733,
770, 700, 749, 867, 897, 805, 789, 749, 703, 719, 770, 628,
768, 412, 932, 652, 749, 760, 773, 905, 865, 876, 711, 752,
722, 795, 803, 781, 765, 730, 711, 738, 725, 746, 811, 859,
881, 800, 822, 584, 956, 595, 800, 749, 1506]
rri = RRi(rri_vals)
smoothed = smoothness_priors(rri)
print(f'Total smoothed values: {len(smoothed.values)}; values < 0: {len(smoothed.values[smoothed.values < 0])}')
poly_detrended = polynomial_detrend(rri)
print(f'Total polynomially detrended values: {len(poly_detrended.values)}; values < 0: {len(poly_detrended.values[poly_detrended.values < 0])}')
sg_detrended = sg_detrend(rri)
print(f'Total sg detrended values: {len(sg_detrended.values)}; values < 0: {len(sg_detrended.values[sg_detrended.values < 0])}')