Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception while comparing empty strings #67

Closed
akoshulian-exos opened this issue Aug 27, 2021 · 1 comment · Fixed by #74
Closed

Exception while comparing empty strings #67

akoshulian-exos opened this issue Aug 27, 2021 · 1 comment · Fixed by #74
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@akoshulian-exos
Copy link

akoshulian-exos commented Aug 27, 2021

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'
@nicoddemus nicoddemus added bug Something isn't working help wanted Extra attention is needed labels Aug 30, 2021
@nicoddemus
Copy link
Member

Thanks @akoshulian-exos for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants