Repository: alteryx/woodwork
Pull request #1534 (2022-09-28 20:17:27)

Fix Dependence bugs

codecov[bot]: # [Codecov](https://codecov.io/gh/alteryx/woodwork/pull/1534?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx) Report
> Merging [#1534](https://codecov.io/gh/alteryx/woodwork/pull/1534?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx) (99a0b62) into [main](https://codecov.io/gh/alteryx/woodwork/commit/0cad75ff1ab2cf09f8210ad310318042138c2b99?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx) (0cad75f) will **decrease** coverage by `81.58%`.
> The diff coverage is `0.00%`.

```diff
@@             Coverage Diff             @@
##             main    #1534       +/-   ##
===========================================
- Coverage   98.91%   17.32%   -81.59%     
===========================================
  Files          91       91               
  Lines       10766    10769        +3     
===========================================
- Hits        10649     1866     -8783     
- Misses        117     8903     +8786     
```


| [Impacted Files](https://codecov.io/gh/alteryx/woodwork/pull/1534?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx) | Coverage Δ | |
|---|---|---|
| [.../statistics\_utils/\_calculate\_dependence\_measure.py](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx#diff-d29vZHdvcmsvc3RhdGlzdGljc191dGlscy9fY2FsY3VsYXRlX2RlcGVuZGVuY2VfbWVhc3VyZS5weQ==) | `18.42% <0.00%> (-81.58%)` | :arrow_down: |
| [...rk/statistics\_utils/\_convert\_ordinal\_to\_numeric.py](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx#diff-d29vZHdvcmsvc3RhdGlzdGljc191dGlscy9fY29udmVydF9vcmRpbmFsX3RvX251bWVyaWMucHk=) | `16.66% <0.00%> (-83.34%)` | :arrow_down: |
| [woodwork/tests/accessor/test\_statistics.py](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx#diff-d29vZHdvcmsvdGVzdHMvYWNjZXNzb3IvdGVzdF9zdGF0aXN0aWNzLnB5) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [woodwork/tests/test\_config.py](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx#diff-d29vZHdvcmsvdGVzdHMvdGVzdF9jb25maWcucHk=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [woodwork/tests/test\_version.py](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx#diff-d29vZHdvcmsvdGVzdHMvdGVzdF92ZXJzaW9uLnB5) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [woodwork/tests/utils/test\_utils.py](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx#diff-d29vZHdvcmsvdGVzdHMvdXRpbHMvdGVzdF91dGlscy5weQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [woodwork/tests/utils/test\_concat.py](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx#diff-d29vZHdvcmsvdGVzdHMvdXRpbHMvdGVzdF9jb25jYXQucHk=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [woodwork/tests/type\_system/conftest.py](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx#diff-d29vZHdvcmsvdGVzdHMvdHlwZV9zeXN0ZW0vY29uZnRlc3QucHk=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [woodwork/tests/utils/test\_read\_file.py](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx#diff-d29vZHdvcmsvdGVzdHMvdXRpbHMvdGVzdF9yZWFkX2ZpbGUucHk=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [woodwork/tests/accessor/test\_indexers.py](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx#diff-d29vZHdvcmsvdGVzdHMvYWNjZXNzb3IvdGVzdF9pbmRleGVycy5weQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| ... and [58 more](https://codecov.io/gh/alteryx/woodwork/pull/1534/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx) | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alteryx)


Patch:
diff --git a/docs/source/release_notes.rst b/docs/source/release_notes.rst
index 079d3e8..2186594 100644
--- a/docs/source/release_notes.rst
+++ b/docs/source/release_notes.rst
@@ -3,15 +3,17 @@
 Release Notes
 -------------
 
-.. Future Release
-  ==============
+Future Release
+==============
     * Enhancements
     * Fixes
+        * Fixed bug relating to ``dependence`` calculations to ensure columns exist in dataframe (:pr:`1534`)
     * Changes
     * Documentation Changes
     * Testing Changes
 
-.. Thanks to the following people for contributing to this release:
+    Thanks to the following people for contributing to this release:
+    :user:`bchen1116`
 
 v0.19.0 September 27, 2022
 ==========================
diff --git a/woodwork/statistics_utils/_calculate_dependence_measure.py b/woodwork/statistics_utils/_calculate_dependence_measure.py
index 2e2d2c7..443fc23 100644
--- a/woodwork/statistics_utils/_calculate_dependence_measure.py
+++ b/woodwork/statistics_utils/_calculate_dependence_measure.py
@@ -38,9 +38,10 @@ def _calculate_dependence_measure(
     Returns:
         None
     """
+    column_pairs = []
     if target_col is None:
         column_pairs = itertools.combinations(col_names, 2)
-    else:
+    elif target_col in col_names:
         column_pairs = [(x, target_col) for x in col_names if x != target_col]
     for a_col, b_col in column_pairs:
         result = results[(a_col, b_col)]
diff --git a/woodwork/statistics_utils/_convert_ordinal_to_numeric.py b/woodwork/statistics_utils/_convert_ordinal_to_numeric.py
index 4fa1818..0790aef 100644
--- a/woodwork/statistics_utils/_convert_ordinal_to_numeric.py
+++ b/woodwork/statistics_utils/_convert_ordinal_to_numeric.py
@@ -11,5 +11,6 @@ def _convert_ordinal_to_numeric(schema, data):
     """
     columns = [k for k, v in schema.logical_types.items() if "Ordinal" in str(v)]
     for col_name in columns:
-        order = list(schema.columns[col_name].logical_type.order)
-        data[col_name] = data[col_name].apply(lambda x: order.index(x))
+        if col_name in data:
+            order = list(schema.columns[col_name].logical_type.order)
+            data[col_name] = data[col_name].apply(lambda x: order.index(x))


Test patch:
diff --git a/woodwork/tests/accessor/test_statistics.py b/woodwork/tests/accessor/test_statistics.py
index f0f139d..8c3a4d6 100644
--- a/woodwork/tests/accessor/test_statistics.py
+++ b/woodwork/tests/accessor/test_statistics.py
@@ -2117,16 +2117,30 @@ def test_convert_ordinal_to_numeric():
         },
     )
     df.ww.init(logical_types={"strs2": Ordinal(order=["hi", "bye"])})
-    data = {column: df[column] for column in df.copy()}
+    data = {column: df[column] for column in df.copy() if column != "ints2"}
     result = [0 if x == "hi" else 1 for x in data["strs2"].values]
     _convert_ordinal_to_numeric(df.ww.schema, data)
-    for cols in df.columns:
+    for cols in data.keys():
         if cols != "strs2":
             assert all(data[cols] == df[cols])
         else:
             assert all(data["strs2"].values == result)
 
 
+def test_dependence_with_object_target():
+    df = pd.DataFrame(
+        {
+            "ints1": pd.Series([1, 2, 3, 2]),
+            "strs": pd.Series(["hi", "hi", "hi", "hi"]),
+            "target_y": pd.Series([True, False, False, pd.NA]),
+        },
+    )
+    df.ww.init()
+    res = df.ww.dependence(target_col="target_y")
+    assert "pearson" not in res.columns
+    assert "spearman" not in res.columns
+
+
 def test_box_plot_ignore_zeros():
     zeros_df = pd.Series(list(range(1, 100)) + [0] * 100)
     no_zeros_df = pd.Series(range(1, 100))