Skip to content

Commit 1965703

Browse files
committed
Add tests + remove duplicate checks in scale function
1 parent 9a0732e commit 1965703

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

eda_utils_py/eda_utils_py.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def scale(dataframe, columns, scaler="standard"):
333333
if col not in list(dataframe.columns):
334334
raise Exception("The given column names must exist in the given dataframe.")
335335

336-
# Check if all input columns in num_col are numeric columns
336+
# Check if all input columns in columns are numeric columns
337337
for col in columns:
338338
if not is_numeric_dtype(dataframe[col]):
339339
raise Exception("The given numerical columns must all be numeric.")
@@ -342,16 +342,6 @@ def scale(dataframe, columns, scaler="standard"):
342342
if not isinstance(scaler, str):
343343
raise TypeError("Scaler must be of type str")
344344

345-
# Check if all input columns exist in the input data
346-
for col in columns:
347-
if col not in list(dataframe.columns):
348-
raise Exception("The given column names must exist in the given dataframe.")
349-
350-
# Check if all input columns in num_col are numeric columns
351-
for col in columns:
352-
if not is_numeric_dtype(dataframe[col]):
353-
raise Exception("The given columns must all be numeric.")
354-
355345
scaled_df = None
356346
if scaler == "minmax":
357347
scaled_df = _minmax(dataframe[columns])

tests/test_eda_utils_py.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,22 @@ def test_scaler():
225225
mock_df_2, ["col1", "col2"], scaler="minmax"
226226
)
227227

228+
# Test if the imput is not dataFrame
229+
with raises(TypeError):
230+
eda_utils_py.outlier_identifier("A string")
231+
232+
# Tests if contents of columns is not of type str
233+
with raises(TypeError):
234+
eda_utils_py.cor_map(mock_df_1, (1, 2, 3, 4))
235+
236+
# Tests if columns do not exist in the dataframe
237+
with raises(Exception):
238+
eda_utils_py.cor_map(mock_df_1, ['one', 'two'])
239+
240+
# Tests if if not all columns in columns are numeric
241+
with raises(Exception):
242+
eda_utils_py.cor_map(mock_df_1, {'col1': "1", 'col2': "3"})
243+
228244
# Tests whether data is not of type pd.Dataframe raises TypeError
229245
with raises(TypeError):
230246
eda_utils_py.scale([14, None, 3, 27])

0 commit comments

Comments
 (0)