# Path: cotede/qctests/digit_roll_over.py
# class DigitRollOver(QCCheckVar):
#     def set_features(self):
#         self.features = {"rate_of_change": rate_of_change(self.data[self.varname])}
# 
#     def test(self):
#         self.flags = {}
#         try:
#             threshold = self.cfg["threshold"]
#         except KeyError:
#             module_logger.debug(
#                 "Deprecated cfg format. It should contain a threshold item."
#             )
#             threshold = self.cfg
# 
#         assert (
#             (np.size(threshold) == 1)
#             and (threshold is not None)
#             and (np.isfinite(threshold))
#         )
# 
#         feature = ma.absolute(self.features["rate_of_change"])
# 
#         flag = np.zeros(np.shape(self.data[self.varname]), dtype="i1")
#         flag[feature > threshold] = self.flag_bad
#         flag[feature <= threshold] = self.flag_good
#         x = np.atleast_1d(self.data[self.varname])
#         flag[ma.getmaskarray(x) | ~np.isfinite(x)] = 9
#         self.flags["digit_roll_over"] = flag
# 
# Path: tests/data.py
# class DummyData(object):
#     def __init__(self):
#         self.attrs = {
#                 'datetime': datetime(2016,6,4),
#                 'LATITUDE': 15, 'LONGITUDE': -38}
#         self.data = {
#                 'PRES': ma.fix_invalid(
#                     [2, 6, 10, 21, 44, 79, 100, 150,
#                         200, 400, 410, 650, 1000, 2000, 5000]),
#                 'TEMP': ma.fix_invalid(
#                     [25.32, 25.34, 25.34, 25.31, 24.99, 23.46, 21.85, 17.95,
#                         15.39, 11.08, 6.93, 7.93, 5.71, 3.58, np.nan]),
#                 'PSAL': ma.fix_invalid(
#                     [36.49, 36.51, 36.52, 36.53, 36.59, 36.76, 36.81, 36.39,
#                         35.98, 35.30, 35.28, 34.93, 34.86, np.nan, np.nan])}
# 
#     def __getitem__(self, key):
#         return self.data[key]
# 
#     def keys(self):
#         return self.data.keys()
# 
#     @property
#     def attributes(self):
#         print('attributes will be removed. Use attrs instead!')
#         return self.attrs
# 
# Path: tests/qctests/compare.py
# def compare_input_types(Procedure, cfg):
#     compare_tuple(Procedure, cfg)
#     compare_pandas(Procedure, cfg)
#     compare_xarray(Procedure, cfg)


import numpy as np
from numpy import ma
from cotede.qctests import DigitRollOver
from ..data import DummyData
from .compare import compare_input_types
    cfg = {"threshold": 3}
    compare_input_types(DigitRollOver, cfg)


def test_standard_dataset():
    profile = DummyData()

    features = {
        "rate_of_change": [
            np.nan,
            0.02,
            0.0,
            -0.03,
            -0.32,
            -1.53,
            -1.61,
            -3.9,
            -2.56,
            -4.31,
            -4.15,
            1,
            -2.22,
            -2.13,
            np.nan,
        ]
    }
    flags = {"digit_roll_over": [0, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 1, 1, 1, 9]}

    cfg = {"threshold": 2.5}


# Path: cotede/qctests/digit_roll_over.py
# class DigitRollOver(QCCheckVar):
#     def set_features(self):
#         self.features = {"rate_of_change": rate_of_change(self.data[self.varname])}
# 
#     def test(self):
#         self.flags = {}
#         try:
#             threshold = self.cfg["threshold"]
#         except KeyError:
#             module_logger.debug(
#                 "Deprecated cfg format. It should contain a threshold item."
#             )
#             threshold = self.cfg
# 
#         assert (
#             (np.size(threshold) == 1)
#             and (threshold is not None)
#             and (np.isfinite(threshold))
#         )
# 
#         feature = ma.absolute(self.features["rate_of_change"])
# 
#         flag = np.zeros(np.shape(self.data[self.varname]), dtype="i1")
#         flag[feature > threshold] = self.flag_bad
#         flag[feature <= threshold] = self.flag_good
#         x = np.atleast_1d(self.data[self.varname])
#         flag[ma.getmaskarray(x) | ~np.isfinite(x)] = 9
#         self.flags["digit_roll_over"] = flag
# 
# Path: tests/data.py
# class DummyData(object):
#     def __init__(self):
#         self.attrs = {
#                 'datetime': datetime(2016,6,4),
#                 'LATITUDE': 15, 'LONGITUDE': -38}
#         self.data = {
#                 'PRES': ma.fix_invalid(
#                     [2, 6, 10, 21, 44, 79, 100, 150,
#                         200, 400, 410, 650, 1000, 2000, 5000]),
#                 'TEMP': ma.fix_invalid(
#                     [25.32, 25.34, 25.34, 25.31, 24.99, 23.46, 21.85, 17.95,
#                         15.39, 11.08, 6.93, 7.93, 5.71, 3.58, np.nan]),
#                 'PSAL': ma.fix_invalid(
#                     [36.49, 36.51, 36.52, 36.53, 36.59, 36.76, 36.81, 36.39,
#                         35.98, 35.30, 35.28, 34.93, 34.86, np.nan, np.nan])}
# 
#     def __getitem__(self, key):
#         return self.data[key]
# 
#     def keys(self):
#         return self.data.keys()
# 
#     @property
#     def attributes(self):
#         print('attributes will be removed. Use attrs instead!')
#         return self.attrs
# 
# Path: tests/qctests/compare.py
# def compare_input_types(Procedure, cfg):
#     compare_tuple(Procedure, cfg)
#     compare_pandas(Procedure, cfg)
#     compare_xarray(Procedure, cfg)


# Path: tests/qctests/test_qc_digit_roll_over.py
import numpy as np
from numpy import ma
from cotede.qctests import DigitRollOver
from ..data import DummyData
from .compare import compare_input_types

    cfg = {"threshold": 3}
    compare_input_types(DigitRollOver, cfg)


def test_standard_dataset():
    profile = DummyData()

    features = {
        "rate_of_change": [
            np.nan,
            0.02,
            0.0,
            -0.03,
            -0.32,
            -1.53,
            -1.61,
            -3.9,
            -2.56,
            -4.31,
            -4.15,
            1,
            -2.22,
            -2.13,
            np.nan,
        ]
    }
    flags = {"digit_roll_over": [0, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 1, 1, 1, 9]}

    cfg = {"threshold": 2.5}


    y = DigitRollOver(profile, "TEMP", cfg)