How to use test_floats method in assertpy

Best Python code snippet using assertpy_python

test_cleansing.py

Source:test_cleansing.py Github

copy

Full Screen

1import pytest2import numpy as np3import pandas as pd4from housinglib.cleansing import drop_precision, fill_na_real, data_cleaning5def test_drop_precision():6 """Checks if drop_precision function works correctly: drops precision,7 keeps shape intact and doesn't change values."""8 rng = np.random.default_rng()9 test_floats = pd.DataFrame(rng.random((100, 10), dtype='float64'),10 columns=['f_' + str(n) for n in range(10)])11 test_ints = pd.DataFrame(rng.integers(0, 10, (100, 10), dtype='int64'),12 columns=['i_' + str(n) for n in range(10)])13 test_df = pd.concat([test_ints, test_floats], axis=1)14 result = drop_precision(test_df)15 assert result.shape == test_df.shape16 old_int_cols = test_df.select_dtypes(include='int64').columns17 new_int_cols = result.select_dtypes(include='int32').columns18 assert (old_int_cols == new_int_cols).all()19 old_float_cols = test_df.select_dtypes(include='float64').columns20 new_float_cols = result.select_dtypes(include='float32').columns21 assert (old_float_cols == new_float_cols).all()22 assert np.allclose(test_df.values, result.values)23def test_fill_na_real():24 """Checks if fill_na_real function works correctly: fills all NaNs, doesn't change shape25 and fills with correct values."""26 rng = np.random.default_rng()27 test_floats = pd.DataFrame(rng.random((100, 10), dtype='float64'),28 columns=['f_' + str(n) for n in range(10)])29 test_ints = pd.DataFrame(rng.integers(0, 10, (100, 10), dtype='int32'),30 columns=['i_' + str(n) for n in range(10)])31 test_df = pd.concat([test_floats, test_ints], axis=1)32 nan_idx_x = rng.choice(100, size=250)33 nan_idx_y = rng.choice(20, size=250)34 for i in range(250):35 test_df.iloc[nan_idx_x[i], nan_idx_y[i]] = np.NaN36 fill_values = pd.concat([test_df.iloc[:, :10].mean(),37 test_df.iloc[:, 10:].median()], axis=0)38 result = fill_na_real(test_df)39 assert result.shape[0] == test_df.shape[0]40 assert result.notna().all(axis=None)41 for i in range(250):42 assert result.iloc[nan_idx_x[i], nan_idx_y[i]] == fill_values[nan_idx_y[i]]43@pytest.mark.parametrize('lower_precision',44 [True, False])45def test_data_cleaning(lower_precision):46 """Checks if processed DataFrame does not make anything exceptionally bad with data.47 Also checks if 'lower_precision' parameter is working."""48 raw = pd.read_table('./data/raw/AmesHousing.txt', index_col=0)49 df = data_cleaning(raw, lower_precision)50 assert df.shape[0] > 051 assert df.shape[1] > 052 assert df.notna().all(axis=None)53 if lower_precision:54 assert 'int64' not in df.dtypes.values...

Full Screen

Full Screen

test_xor16.py

Source:test_xor16.py Github

copy

Full Screen

1from pyxorfilter import Xor162import random3def test_xor16_int():4 xor_filter = Xor16(100)5 test_lst = random.sample(range(0, 1000), 100)6 xor_filter.populate(test_lst.copy())7 for i in test_lst:8 assert xor_filter.contains(i) == True9 for i in random.sample(range(1000, 3000), 500):10 assert xor_filter.contains(i) == False11def test_xor16_int_iterable():12 xor_filter = Xor16(100)13 xor_filter.populate(range(50))14 for i in range(50):15 assert xor_filter.contains(i) == True16def test_xor16_strings():17 xor_filter = Xor16(10)18 test_str = ["あ", "/dev/null; touch /tmp/blns.fail ; echo", "अ", "Normal", "122"]19 xor_filter.populate(test_str.copy())20 for test in test_str:21 assert xor_filter.contains(test) == True22 test_str2 = ["月", "क", "12", "delta"]23 for i in test_str2:24 assert xor_filter.contains(i) == False25def test_xor16_floats():26 xor_filter = Xor16(10)27 test_floats = [1.23, 9999.88, 323.43, 0.0]28 xor_filter.populate(test_floats.copy())29 for i in test_floats:30 assert xor_filter.contains(i) == True31 test_floats2 = [-1.23, 1.0, 0.1, 676.5, 1.234]32 for i in test_floats2:33 assert xor_filter.contains(i) == False34def test_xor16_all():35 xor_filter = Xor16(5)36 test_str = ["string", 51, 0.0, 12.3]37 xor_filter.populate(test_str.copy())38 for i in test_str:39 assert xor_filter.contains(i) == True40 test_str2 = [12, "४", 0.1]41 for i in test_str2:...

Full Screen

Full Screen

test_xor8.py

Source:test_xor8.py Github

copy

Full Screen

1from pyxorfilter import Xor82from random import sample3def test_xor8_int():4 xor_filter = Xor8(50)5 xor_filter.populate([_ for _ in range(50)])6 for i in range(50):7 assert xor_filter.contains(i) == True8def test_xor8_int_iterable():9 xor_filter = Xor8(50)10 xor_filter.populate(range(50))11 for i in range(50):12 assert xor_filter.contains(i) == True13def test_xor8_strings():14 xor_filter = Xor8(10)15 test_str = ["あ", "/dev/null; touch /tmp/blns.fail ; echo", "अ", "Normal", "122"]16 xor_filter.populate(test_str.copy())17 for i in test_str:18 assert xor_filter.contains(i) == True19def test_xor8_floats():20 xor_filter = Xor8(10)21 test_floats = [1.23, 9999.88, 323.43, 0.0]22 xor_filter.populate(test_floats.copy())23 for i in test_floats:24 assert xor_filter.contains(i) == True25def test_xor8_all():26 xor_filter = Xor8(5)27 test_str = ["string", 51, 0.0, 12.3]28 xor_filter.populate(test_str.copy())29 for i in test_str:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run assertpy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful