Repository: fairlearn/fairlearn

Issue:
Tests are failing with pandas 1.4.0
In #1011 @britneyting encountered the following issue in Python 3.9 tests using pandas 1.4.0 which I can reproduce locally:
```
=================================== FAILURES ===================================
___________________ TestSingleFeature.test_from_dict_failure ___________________

self = <test.unit.metrics.test_metricframe_process_features.TestSingleFeature object at 0x7f90b7c239d0>

    def test_from_dict_failure(self):
        r_f, y_true = self._get_raw_data()
        raw_feature = {'Mine!': np.asarray(r_f).reshape(-1, 1)}
        target = _get_raw_MetricFrame()
        msg = "DataFrame.from_dict() failed on sensitive features. "\
            "Please ensure each array is strictly 1-D."
        with pytest.raises(ValueError) as ve:
            _ = target._process_features("Unused", raw_feature, y_true)
        assert msg == ve.value.args[0]
        assert ve.value.__cause__ is not None
        assert isinstance(ve.value.__cause__, ValueError)
        # Ensure we got the gnomic pandas message
>       assert ve.value.__cause__.args[0] == 'If using all scalar values, you must pass an index'
E       AssertionError: assert 'Per-column a...1-dimensional' == 'If using all ...pass an index'
E         - Per-column arrays must each be 1-dimensional
E         + If using all scalar values, you must pass an index

test/unit/metrics/test_metricframe_process_features.py:105: AssertionError
```

It seems like the error message changed to "Per-column arrays must each be 1-dimensional"
Does that sound about right @riedgar-ms ? If so, we can change that string. Since it doesn't sound similar I wanted to at least check with you (assuming you wrote the test).

Comments:

Patch:
diff --git a/fairlearn/metrics/_metric_frame.py b/fairlearn/metrics/_metric_frame.py
index c055dee..19bef45 100644
--- a/fairlearn/metrics/_metric_frame.py
+++ b/fairlearn/metrics/_metric_frame.py
@@ -22,7 +22,8 @@ _VALID_ERROR_STRING = ['raise', 'coerce']
 _VALID_GROUPING_FUNCTION = ['min', 'max']
 
 _SF_DICT_CONVERSION_FAILURE = "DataFrame.from_dict() failed on sensitive features. " \
-    "Please ensure each array is strictly 1-D."
+    "Please ensure each array is strictly 1-D. " \
+    "The __cause__ field of this exception may contain further information."
 _BAD_FEATURE_LENGTH = "Received a feature of length {0} when length {1} was expected"
 _SUBGROUP_COUNT_WARNING = "Found {0} subgroups. Evaluation may be slow"
 _FEATURE_LIST_NONSCALAR = "Feature lists must be of scalar types"


Test patch:
diff --git a/test/unit/metrics/test_metricframe_process_features.py b/test/unit/metrics/test_metricframe_process_features.py
index db09c09..cb64b3c 100644
--- a/test/unit/metrics/test_metricframe_process_features.py
+++ b/test/unit/metrics/test_metricframe_process_features.py
@@ -95,14 +95,12 @@ class TestSingleFeature():
         raw_feature = {'Mine!': np.asarray(r_f).reshape(-1, 1)}
         target = _get_raw_MetricFrame()
         msg = "DataFrame.from_dict() failed on sensitive features. "\
-            "Please ensure each array is strictly 1-D."
+            "Please ensure each array is strictly 1-D. "\
+            "The __cause__ field of this exception may contain further information."
         with pytest.raises(ValueError) as ve:
             _ = target._process_features("Unused", raw_feature, y_true)
         assert msg == ve.value.args[0]
         assert ve.value.__cause__ is not None
-        assert isinstance(ve.value.__cause__, ValueError)
-        # Ensure we got the gnomic pandas message
-        assert ve.value.__cause__.args[0] == 'If using all scalar values, you must pass an index'
 
 
 class TestTwoFeatures():