Repository: ESSS/pytest-regressions (language: python)

Issue:
Exception while comparing empty strings
Minimal, reproducible example:

```
def test_frame(dataframe_regression):
    df = pd.DataFrame.from_records([
        {
            'a': 'a',
            'b': 'b'
        },
        {
            'a': 'a1',
            'b': ''
        },
    ])

    dataframe_regression.check(df)

```

This test results in rising the following exception:
`{TypeError}unsupported operand type(s) for -: 'str' and 'str'`

The issue arises because the empty string is converted to nan while reading a csv file containing the dataframe.


```
Traceback (most recent call last):
  File ".../venv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-b86ebfe209ab>", line 1, in <module>
    dataframe_regression.check(df)
  File ".../venv/lib/python3.7/site-packages/pytest_regressions/dataframe_regression.py", line 260, in check
    force_regen=self._force_regen,
  File ".../venv/lib/python3.7/site-packages/pytest_regressions/common.py", line 153, in perform_regression_check
    check_fn(obtained_filename, filename)
  File ".../venv/lib/python3.7/site-packages/pytest_regressions/dataframe_regression.py", line 143, in _check_fn
    diffs = np.abs(obtained_column - expected_column)[diff_ids]
  File ".../venv/lib/python3.7/site-packages/pandas/core/ops/common.py", line 65, in new_method
    return method(self, other)
  File ".../venv/lib/python3.7/site-packages/pandas/core/arraylike.py", line 97, in __sub__
    return self._arith_method(other, operator.sub)
  File ".../venv/lib/python3.7/site-packages/pandas/core/series.py", line 4998, in _arith_method
    result = ops.arithmetic_op(lvalues, rvalues, op)
  File ".../venv/lib/python3.7/site-packages/pandas/core/ops/array_ops.py", line 189, in arithmetic_op
    res_values = _na_arithmetic_op(lvalues, rvalues, op)
  File ".../venv/lib/python3.7/site-packages/pandas/core/ops/array_ops.py", line 149, in _na_arithmetic_op
    result = _masked_arith_op(left, right, op)
  File ".../venv/lib/python3.7/site-packages/pandas/core/ops/array_ops.py", line 91, in _masked_arith_op
    result[mask] = op(xrav[mask], yrav[mask])
TypeError: unsupported operand type(s) for -: 'str' and 'str'
```





Discussion / hints:
Thanks @akoshulian-exos for the report!

Fix patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 47f9f29..ab09660 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -2,6 +2,7 @@
 ------------------
 
 * `#54 <https://github.com/ESSS/pytest-regressions/pull/54>`__: New ``--with-test-class-names`` command-line flag to consider test class names when composing the expected and obtained data filenames. Needed when the same module contains different classes with the same method names.
+* `#74 <https://github.com/ESSS/pytest-regressions/pull/74>`__: Fix ``empty string bug`` on dataframe regression.
 
 2.2.0 (2020-01-27)
 ------------------


Test patch:
diff --git a/src/pytest_regressions/dataframe_regression.py b/src/pytest_regressions/dataframe_regression.py
index bfe4617..86620ea 100644
--- a/src/pytest_regressions/dataframe_regression.py
+++ b/src/pytest_regressions/dataframe_regression.py
@@ -97,8 +97,8 @@ def _check_fn(self, obtained_filename, expected_filename):
 
         __tracebackhide__ = True
 
-        obtained_data = pd.read_csv(str(obtained_filename))
-        expected_data = pd.read_csv(str(expected_filename))
+        obtained_data = pd.read_csv(str(obtained_filename), keep_default_na=False)
+        expected_data = pd.read_csv(str(expected_filename), keep_default_na=False)
 
         comparison_tables_dict = {}
         for k in obtained_data.keys():
diff --git a/tests/test_dataframe_regression.py b/tests/test_dataframe_regression.py
index 687c000..f17518d 100644
--- a/tests/test_dataframe_regression.py
+++ b/tests/test_dataframe_regression.py
@@ -252,3 +252,14 @@ def test_non_pandas_dataframe(dataframe_regression):
         " *Object with type '%s' was given." % (str(type(data)),),
     ):
         dataframe_regression.check(data)
+
+
+def test_frame(dataframe_regression):
+    df = pd.DataFrame.from_records(
+        [
+            {"a": "a", "b": "b"},
+            {"a": "a1", "b": ""},
+        ]
+    )
+
+    dataframe_regression.check(df)
diff --git a/tests/test_dataframe_regression/test_frame.csv b/tests/test_dataframe_regression/test_frame.csv
new file mode 100644
index 0000000..9fc433b
--- /dev/null
+++ b/tests/test_dataframe_regression/test_frame.csv
@@ -0,0 +1,3 @@
+,a,b
+0,a,b
+1,a1,