complexifier 0.2.2__py3-none-any.whl → 0.2.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
complexifier/main.py CHANGED
@@ -19,19 +19,19 @@ def create_spag_error(word: str) -> str:
19
19
  weight = random.randint(1, 100)
20
20
  match weight:
21
21
  case 1:
22
- return error_object.missing_char()
22
+ return error_object.missing_char().result
23
23
  case 2:
24
- return error_object.char_swap()
24
+ return error_object.char_swap().result
25
25
  case 3:
26
- return error_object.extra_char()
26
+ return error_object.extra_char().result
27
27
  case 4:
28
- return error_object.nearby_char()
28
+ return error_object.nearby_char().result
29
29
  case 5:
30
- return error_object.similar_char()
30
+ return error_object.similar_char().result
31
31
  case 6:
32
- return error_object.random_space()
32
+ return error_object.random_space().result
33
33
  case 7:
34
- return error_object.repeated_char()
34
+ return error_object.repeated_char().result
35
35
  case 8:
36
36
  return word.lower()
37
37
  case 9:
@@ -152,7 +152,7 @@ def duplicate_rows(df: pd.DataFrame, sample_size=None) -> pd.DataFrame:
152
152
  pd.DataFrame: The DataFrame with duplicate rows added.
153
153
  """
154
154
  if not sample_size:
155
- sample_size = random.randint(len(df[col]) // 100, len(df[col]) // 10)
155
+ sample_size = random.randint(len(df) // 100, len(df) // 10)
156
156
  new_rows = df.sample(sample_size)
157
157
  return pd.concat([df, new_rows])
158
158
 
@@ -180,8 +180,10 @@ def add_nulls(
180
180
  raise TypeError(f"Columns is type {type(columns)} but expected str or list")
181
181
 
182
182
  for col in columns:
183
- indices_to_none = df.sample(
184
- len(df) * random.randint(min_percent, max_percent) // 100
185
- ).index
183
+ chosen_percent = random.randint(min_percent, max_percent) / 100
184
+ sample_size = round(len(df)*chosen_percent)
185
+ if sample_size == 0:
186
+ sample_size = 1
187
+ indices_to_none = df.sample(sample_size).index
186
188
  df.loc[indices_to_none, col] = None
187
189
  return df
complexifier/test_main.py CHANGED
@@ -1,12 +1,14 @@
1
1
  import pytest
2
2
  import pandas as pd
3
- from .main import (create_spag_error,
4
- introduce_spag_error,
5
- add_or_subtract_outliers,
6
- add_standard_deviations,
7
- duplicate_rows,
8
- add_nulls)
9
-
3
+ from math import floor
4
+ from .main import (
5
+ create_spag_error,
6
+ introduce_spag_error,
7
+ add_or_subtract_outliers,
8
+ add_standard_deviations,
9
+ duplicate_rows,
10
+ add_nulls
11
+ )
10
12
 
11
13
  @pytest.fixture
12
14
  def sample_df():
@@ -20,51 +22,60 @@ def sample_df():
20
22
  'Salary': [70000, 80000, 72000, 95000, 67000]
21
23
  })
22
24
 
23
-
24
- def test_create_spag_error():
25
+ @pytest.mark.parametrize("word", ["hello", "world", "testword"])
26
+ def test_create_spag_error(word):
25
27
  """
26
- Test that for a word with sufficient length, the function must return a string of same length
28
+ Tests that the word returned is still a string
27
29
  """
28
- word = "hello"
29
30
  error_word = create_spag_error(word)
30
31
  assert isinstance(error_word, str)
31
- assert len(error_word) == len(word)
32
32
 
33
- def test_introduce_spag_error(sample_df):
33
+ @pytest.mark.parametrize("column_name", ["Name", "City"])
34
+ def test_introduce_spag_error(sample_df, column_name):
34
35
  """
35
36
  Test that DataFrame columns contain the potential spelling errors
36
37
  """
37
- df_with_errors = introduce_spag_error(sample_df, columns='Name')
38
- assert 'Name' in df_with_errors.columns
39
- assert all([isinstance(name, str) for name in df_with_errors['Name'].values])
38
+ df_with_errors = introduce_spag_error(sample_df, columns=column_name)
39
+ assert column_name in df_with_errors.columns
40
+ assert all([isinstance(name, str) for name in df_with_errors[column_name].values])
40
41
 
41
- def test_add_or_subtract_outliers(sample_df):
42
+ @pytest.mark.parametrize("column_name", ["Salary"])
43
+ def test_add_or_subtract_outliers(sample_df, column_name):
42
44
  """
43
45
  Test that outliers are added to the numerical columns
44
46
  """
45
- df_with_outliers = add_or_subtract_outliers(sample_df, columns='Salary')
46
- assert 'Salary' in df_with_outliers.columns
47
- assert df_with_outliers['Salary'].dtype == float or df_with_outliers['Salary'].dtype == int
47
+ df_with_outliers = add_or_subtract_outliers(sample_df, columns=column_name)
48
+ assert column_name in df_with_outliers.columns
49
+ assert pd.api.types.is_numeric_dtype(df_with_outliers[column_name])
48
50
 
49
- def test_add_standard_deviations(sample_df):
51
+ @pytest.mark.parametrize("column_name", ["Age", "Salary"])
52
+ def test_add_standard_deviations(sample_df, column_name):
50
53
  """
51
- Test that standard deviations are added to the Age column
54
+ Test that standard deviations are added to the specified column
52
55
  """
53
- df_with_deviations = add_standard_deviations(sample_df, columns='Age')
54
- assert 'Age' in df_with_deviations.columns
55
- assert df_with_deviations['Age'].dtype == float or df_with_deviations['Age'].dtype == int
56
+ df_with_deviations = add_standard_deviations(sample_df, columns=column_name)
57
+ assert column_name in df_with_deviations.columns
58
+ assert pd.api.types.is_numeric_dtype(df_with_deviations[column_name])
56
59
 
57
- def test_duplicate_rows(sample_df):
60
+ @pytest.mark.parametrize("sample_size", [0, 2, 5])
61
+ def test_duplicate_rows(sample_df, sample_size):
58
62
  """
59
63
  Test that duplicate rows are added
60
64
  """
61
- df_with_duplicates = duplicate_rows(sample_df, sample_size=2)
62
- assert len(df_with_duplicates) == len(sample_df) + 2
65
+ df_with_duplicates = duplicate_rows(sample_df, sample_size=sample_size)
66
+ assert len(df_with_duplicates) == len(sample_df) + sample_size
63
67
 
64
- def test_add_nulls(sample_df):
68
+ @pytest.mark.parametrize("column_name,min_percent,max_percent", [
69
+ ("City", 10, 20),
70
+ ("Name", 20, 30)
71
+ ])
72
+ def test_add_nulls(sample_df, column_name, min_percent, max_percent):
65
73
  """
66
74
  Test that nulls are added to the DataFrame
67
75
  """
68
- df_with_nulls = add_nulls(sample_df, columns='City', min_percent=20, max_percent=30)
69
- assert 'City' in df_with_nulls.columns
70
- assert df_with_nulls['City'].isnull().sum() > 0
76
+ df_with_nulls = add_nulls(sample_df, columns=column_name, min_percent=min_percent, max_percent=max_percent)
77
+ assert column_name in df_with_nulls.columns
78
+ null_count = df_with_nulls[column_name].isnull().sum()
79
+ print(df_with_nulls)
80
+ assert float(null_count) >= 0.0
81
+ assert (min_percent*0.01*len(sample_df)) <= null_count <= round(max_percent*0.01*len(sample_df))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: complexifier
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A library to make data worse
5
5
  Project-URL: Homepage, https://github.com/ruyzambrano/complexifier
6
6
  Project-URL: Issues, https://github.com/ruyzambrano/complexifier/issues
@@ -0,0 +1,7 @@
1
+ complexifier/__init__.py,sha256=zDr350exO14Ii8Pj3TXwPuRxIDrEjrg43CpjYABDqh4,19
2
+ complexifier/main.py,sha256=OUyK7kVV2A_pW_kHV1xI_MkyYnoQEEsB0r2TmMF5Sac,6703
3
+ complexifier/test_main.py,sha256=gzy5ajTZKbPTYbhbG2F1Rnnad0kxDu2pK10bCYz8v_0,2942
4
+ complexifier-0.2.3.dist-info/METADATA,sha256=3wEp6WbAIbstzgnmAI9NBeoNjFHIflZULIudxaYditI,2986
5
+ complexifier-0.2.3.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
6
+ complexifier-0.2.3.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
7
+ complexifier-0.2.3.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- complexifier/__init__.py,sha256=zDr350exO14Ii8Pj3TXwPuRxIDrEjrg43CpjYABDqh4,19
2
- complexifier/main.py,sha256=bi8XYFpfh05TgYDefBFz8Y5vFl0-Wx-dcuZBOAEJdyY,6551
3
- complexifier/test_main.py,sha256=nDg03HGhi_QMox_GAkonkakgOcXDBsuro6AR5mbpyWw,2391
4
- complexifier-0.2.2.dist-info/METADATA,sha256=yrdaeptIdP7SAOERGhVtgta9xLHIydiOg9Ucys3KeN4,2986
5
- complexifier-0.2.2.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
6
- complexifier-0.2.2.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
7
- complexifier-0.2.2.dist-info/RECORD,,