From 40e129f4a80f2779fd265b1ff1703d7db4e3b9f4 Mon Sep 17 00:00:00 2001 From: Philipp Kats Date: Tue, 14 Mar 2023 10:52:23 -0400 Subject: [PATCH 1/2] testing renaming --- dfschema/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dfschema/__init__.py b/dfschema/__init__.py index a431959..20e1a06 100644 --- a/dfschema/__init__.py +++ b/dfschema/__init__.py @@ -1,4 +1,4 @@ -from .validate import validate_df +from .validate import validate_df as validate from .utils import generate_scheme, schema_to_dtypes from .core.core import DfSchema from .core.exceptions import ( @@ -9,7 +9,7 @@ __all__ = [ - "validate_df", + "validate", "DfSchema", "generate_scheme", "schema_to_dtypes", From 3672974f8d7187fd44acac6823c00635d8b88fc7 Mon Sep 17 00:00:00 2001 From: Philipp Kats Date: Tue, 14 Mar 2023 10:58:03 -0400 Subject: [PATCH 2/2] rename function --- dfschema/__init__.py | 2 +- dfschema/validate.py | 2 +- notebooks/benchmarks.ipynb | 12 ++++++------ tests/test_categorical.py | 18 +++++++++--------- tests/test_invalid.py | 4 ++-- tests/test_numeric.py | 12 ++++++------ tests/test_validate.py | 24 ++++++++++++------------ 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/dfschema/__init__.py b/dfschema/__init__.py index 20e1a06..7c1afd5 100644 --- a/dfschema/__init__.py +++ b/dfschema/__init__.py @@ -1,4 +1,4 @@ -from .validate import validate_df as validate +from .validate import validate from .utils import generate_scheme, schema_to_dtypes from .core.core import DfSchema from .core.exceptions import ( diff --git a/dfschema/validate.py b/dfschema/validate.py index 718e5de..8b635a6 100644 --- a/dfschema/validate.py +++ b/dfschema/validate.py @@ -3,7 +3,7 @@ from .core import DfSchema -def validate_df(df: pd.DataFrame, schema: dict, summary: bool = True) -> None: +def validate(df: pd.DataFrame, schema: dict, summary: bool = True) -> None: """validate dataframe against the schema validate dataframe agains the schema as a dictionary. will raise diff --git a/notebooks/benchmarks.ipynb b/notebooks/benchmarks.ipynb index 3e9450f..82d8d84 100644 --- a/notebooks/benchmarks.ipynb +++ b/notebooks/benchmarks.ipynb @@ -124,12 +124,12 @@ "source": [ "tests = {\n", " 'SE': 'validate_df(sample, schema_p1)',\n", - " 'dfs_s_p1': 'dfs.validate_df(sample, schema_p1, summary=True)',\n", - " 'dfs_f_p1': 'dfs.validate_df(sample, schema_p1, summary=False)',\n", - " 'dfs_s_p2': 'dfs.validate_df(sample, schema_p2, summary=True)',\n", - " 'dfs_f_p2': 'dfs.validate_df(sample, schema_p2, summary=False)',\n", - " 'dfs_S_s': 'S.validate_df(sample, summary=True)',\n", - " 'dfs_S_f': 'S.validate_df(sample, summary=False)'\n", + " 'dfs_s_p1': 'dfs.validate(sample, schema_p1, summary=True)',\n", + " 'dfs_f_p1': 'dfs.validate(sample, schema_p1, summary=False)',\n", + " 'dfs_s_p2': 'dfs.validate(sample, schema_p2, summary=True)',\n", + " 'dfs_f_p2': 'dfs.validate(sample, schema_p2, summary=False)',\n", + " 'dfs_S_s': 'S.validate(sample, summary=True)',\n", + " 'dfs_S_f': 'S.validate(sample, summary=False)'\n", "}" ] }, diff --git a/tests/test_categorical.py b/tests/test_categorical.py index 6b6730e..b95ad8e 100644 --- a/tests/test_categorical.py +++ b/tests/test_categorical.py @@ -6,7 +6,7 @@ def test_df_oneof(): - from dfschema import validate_df, DataFrameSummaryError + from dfschema import validate, DataFrameSummaryError df = pd.DataFrame({"x": [1, 2, 3], "y": [0.2, 0.5, 0.99], "z": ["A", "A", "Q"]}) schema = { @@ -19,16 +19,16 @@ def test_df_oneof(): "strict_cols": True, } - validate_df(df, schema) + validate(df, schema) df.loc[1, "z"] = "B" with pytest.raises(DataFrameSummaryError): - validate_df(df, schema) + validate(df, schema) # @given(df=cat_df_include()) def test_df_include(): - from dfschema import validate_df, DataFrameSummaryError + from dfschema import validate, DataFrameSummaryError df = pd.DataFrame({"x": [1, 2, 3], "y": [0.2, 0.5, 0.99], "z": ["A", "Q", "Q"]}) @@ -41,15 +41,15 @@ def test_df_include(): "strict_cols": True, } - validate_df(df, schema) + validate(df, schema) schema["columns"]["z"]["include"].append("B") with pytest.raises(DataFrameSummaryError): - validate_df(df, schema) + validate(df, schema) def test_df_unique(): - from dfschema import validate_df, DataFrameSummaryError + from dfschema import validate, DataFrameSummaryError df = pd.DataFrame({"x": [1, 2, 3], "y": [0.2, 0.5, 0.99], "z": ["A", "B", "C"]}) schema = { @@ -61,9 +61,9 @@ def test_df_unique(): "strict_cols": True, } - validate_df(df, schema) + validate(df, schema) df["z"] = "A" with pytest.raises(DataFrameSummaryError): - validate_df(df, schema) + validate(df, schema) diff --git a/tests/test_invalid.py b/tests/test_invalid.py index 085aea7..faedf71 100644 --- a/tests/test_invalid.py +++ b/tests/test_invalid.py @@ -2,8 +2,8 @@ def test_df_validate_invalid_schema(df1, bad_schema: dict): - from dfschema import validate_df + from dfschema import validate from pydantic import ValidationError with pytest.raises(ValidationError): - validate_df(df1, bad_schema["schema"]) + validate(df1, bad_schema["schema"]) diff --git a/tests/test_numeric.py b/tests/test_numeric.py index 174e599..f6a9c3f 100644 --- a/tests/test_numeric.py +++ b/tests/test_numeric.py @@ -60,16 +60,16 @@ @pytest.mark.parametrize("schema", max_min_correct["df1"]) def test_validate_df1_max_min(df1, schema): - from dfschema import validate_df + from dfschema import validate - validate_df(df1, schema) + validate(df1, schema) @pytest.mark.parametrize("schema", max_min_correct["df2"]) def test_validate_df2_max_min(df2, schema): - from dfschema import validate_df + from dfschema import validate - validate_df(df2, schema) + validate(df2, schema) wrong_schemas_max_min_df2 = [ @@ -84,7 +84,7 @@ def test_validate_df2_max_min(df2, schema): @pytest.mark.parametrize("schema", wrong_schemas_max_min_df2) def test_validate_df2_max_min_raises(df2, schema): - from dfschema import validate_df, DataFrameValidationError + from dfschema import validate, DataFrameValidationError with pytest.raises(DataFrameValidationError): - validate_df(df2, schema) + validate(df2, schema) diff --git a/tests/test_validate.py b/tests/test_validate.py index f3f6994..b6cee55 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -26,9 +26,9 @@ @pytest.mark.parametrize("schema", good_schemas) def test_validate_df(df1, schema): - from dfschema import validate_df + from dfschema import validate - validate_df(df1, schema) + validate(df1, schema) wrong_schemas = [ @@ -48,7 +48,7 @@ def test_validate_df(df1, schema): @pytest.mark.parametrize("schema", wrong_schemas) def test_validate_df_raises(df1, summary, schema): from dfschema import ( - validate_df, + validate, DataFrameValidationError, DataFrameSummaryError, ) @@ -56,7 +56,7 @@ def test_validate_df_raises(df1, summary, schema): e = [DataFrameValidationError, DataFrameSummaryError][summary] with pytest.raises(e): - validate_df(df1, schema, summary=summary) + validate(df1, schema, summary=summary) good_schemas2 = [ @@ -86,16 +86,16 @@ def test_validate_df_raises(df1, summary, schema): @pytest.mark.parametrize("schema", good_schemas2) def test_validate_df2(df2, schema): - from dfschema import validate_df + from dfschema import validate - validate_df(df2, schema) + validate(df2, schema) @pytest.mark.parametrize("summary", [False, True]) @pytest.mark.parametrize("schema", wrong_schemas2) def test_validate_df2_raises(df2, summary, schema): from dfschema import ( - validate_df, + validate, DataFrameValidationError, DataFrameSummaryError, ) @@ -103,7 +103,7 @@ def test_validate_df2_raises(df2, summary, schema): e = [DataFrameValidationError, DataFrameSummaryError][summary] with pytest.raises(e): - validate_df(df2, schema, summary=summary) + validate(df2, schema, summary=summary) good_schemas3 = [ @@ -128,14 +128,14 @@ def test_validate_df2_raises(df2, summary, schema): @pytest.mark.parametrize("schema", good_schemas3) def test_validate_nan_str(df3, schema): - from dfschema import validate_df + from dfschema import validate - validate_df(df3, schema) + validate(df3, schema) @pytest.mark.parametrize("schema", wrong_schemas3) def test_validate_df3_raises(df3, schema): - from dfschema import validate_df, DataFrameValidationError + from dfschema import validate, DataFrameValidationError with pytest.raises(DataFrameValidationError): - validate_df(df3, schema) + validate(df3, schema)