예제 #1
0
def example_failing_verification():
    n_failures = 0
    df = pd.DataFrame({
        'a': [0, 1, 2, 10, pd.np.NaN],
        'b': ['one', 'one', 'two', 'three', pd.np.NaN]
    })
    v = verify_df(df, TDDA_FILE)

    if v.failures > 0:
        print('Correctly failed to verify dataframe that does not satisify '
              'all the constraints in %s' % TDDA_FILE)
        if v.failures != 7 and v.passes != 5:
            print('However, expected 7 failures and 5 passes.\n'
                  'Actual: Failures: %d, Passes: %s.\n'
                  '*** Not great!' % (v.failures, v.passes))
            n_failures = 1
    elif v.failures == 0:
        print('*** Incorrectly verified dataframe that should have failed '
              'against constraints in\n %s.' % TDDA_FILE,
              file=sys.stderr)
        n_failures = 1

    print('\nRESULT AS A STRING:\n')
    print(str(v))
    print('\nRESULT AS A DATAFRAME:\n')
    print(v.to_frame())
    print('\n')
    return n_failures
예제 #2
0
 def testElements92(self):
     csv_path = os.path.join(TESTDATA_DIR, 'elements92.csv')
     df = pd.read_csv(csv_path)
     constraints_path = os.path.join(TESTDATA_DIR, 'elements92.tdda')
     v = verify_df(df, constraints_path)
     self.assertEqual(v.passes, 72)
     self.assertEqual(v.failures, 0)
예제 #3
0
 def testElements118(self):
     csv_path = os.path.join(TESTDATA_DIR, 'elements118.csv')
     df = pd.read_csv(csv_path)
     constraints_path = os.path.join(TESTDATA_DIR, 'elements92.tdda')
     v = verify_df(df, constraints_path, report='fields')
     self.assertEqual(v.passes, 57)
     self.assertEqual(v.failures, 15)
     vdf = v.to_dataframe()
     vdf.sort_values('field', inplace=True)
예제 #4
0
def example_positive_verification():
    n_failures = 0
    df = pd.DataFrame({'a': [2, 4], 'b': ['one', pd.np.NaN]})
    v = verify_df(df, TDDA_FILE)

    if v.failures == 0:
        print('Correctly verified dataframe against constraints in %s.' %
              TDDA_FILE)
    else:
        print('*** Unexpectedly failed to verify dataframe against constraints'
              ' in %s.\nSomething is wrong!' % TDDA_FILE,
              file=sys.stderr)
        print(v)
        n_failures = 1
    return n_failures
예제 #5
0
파일: pdverify.py 프로젝트: ehansis/tdda
def verify_df_from_file(df_path, constraints_path, **kwargs):
    df = load_df(df_path)
    print(verify_df(df, constraints_path, **kwargs))
예제 #6
0
# elements_verify_118.py

from __future__ import print_function
import pandas as pd

from tdda.constraints.pdconstraints import verify_df

df = pd.read_csv('testdata/elements118.csv')
print(verify_df(df, 'elements92.tdda'))
예제 #7
0
import pandas as pd
from tdda.constraints.pdconstraints import verify_df

df = pd.DataFrame({'a': [2, 4], 'b': ['one', pd.np.NaN]})
v = verify_df(df, 'example_constraints.tdda')

print('Passes: %d' % v.passes)
print('Failures: %d\n\n\n' % v.failures)
print(str(v))
print('\n\n')
print(v.to_frame())
예제 #8
0
# elements_verify_118.py

from __future__ import print_function
import pandas as pd

from tdda.constraints.pdconstraints import verify_df

df = pd.read_csv('testdata/elements118.csv')
print(verify_df(df, 'elements118.tdda'))