diff --git a/.gitignore b/.gitignore
index 432450f..588be13 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@ dist/
 .idea/
 *.pyc
 .DS_Store
+.pytest_cache/
 
 # Spark junk
 metastore_db/
@@ -14,4 +15,4 @@ derby.log
 
 *.ipynb*
 docs/doctrees
-docs/.buildinfo
\ No newline at end of file
+docs/.buildinfo
diff --git a/datacompy/core.py b/datacompy/core.py
index e03d75e..0cb0a72 100644
--- a/datacompy/core.py
+++ b/datacompy/core.py
@@ -290,14 +290,8 @@ class Compare(object):
                     self.abs_tol,
                     ignore_spaces)
                 match_cnt = self.intersect_rows[col_match].sum()
-
-                try:
-                    max_diff = (
-                        self.intersect_rows[col_1]
-                        - self.intersect_rows[col_2]).abs().max()
-                except:
-                    max_diff = 0
-
+                max_diff = calculate_max_diff(
+                    self.intersect_rows[col_1], self.intersect_rows[col_2])
                 null_diff = (
                     (self.intersect_rows[col_1].isnull())
                     ^ (self.intersect_rows[col_2].isnull())).sum()
@@ -626,7 +620,7 @@ def columns_equal(col_1, col_2, rel_tol=0, abs_tol=0, ignore_spaces=False):
                         col_1 = col_1.str.strip()
                     if col_2.dtype.kind == 'O':
                         col_2 = col_2.str.strip()
-                        
+
                 if set([col_1.dtype.kind, col_2.dtype.kind]) == set(['M','O']):
                     compare = compare_string_and_date_columns(col_1, col_2)
                 else:
@@ -718,3 +712,23 @@ def temp_column_name(*dataframes):
                 unique = False
         if unique:
             return temp_column
+
+def calculate_max_diff(col_1, col_2):
+    """Get a maximum difference between two columns
+
+    Parameters
+    ----------
+    col_1 : Pandas.Series
+        The first column
+    col_2 : Pandas.Series
+        The second column
+
+    Returns
+    -------
+    Numeric
+        Numeric field, or zero.
+    """
+    try:
+        return (col_1.astype(float) - col_2.astype(float)).abs().max()
+    except:
+        return 0

Max Diff in Report not working if comparing object and numeric datatypes
Although the tolerance values and overall matching seem to work fine when comparing object to float64 or int64, in the summary report, the Max Diff is always 0.000000

Probably can be fixed here with .astype(float)?: https://github.com/capitalone/datacompy/blob/4d7fc4889322e22f487d7cf33cb1554fce3a496d/datacompy/core.py#L295-L297


diff --git a/tests/test_core.py b/tests/test_core.py
index a5eb6e1..329a2df 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -677,3 +677,26 @@ def test_index_with_joins_with_ignore_spaces():
     assert compare.all_columns_match()
     assert compare.all_rows_overlap()
     assert compare.intersect_rows_match()
+
+
+MAX_DIFF_DF = pd.DataFrame({
+    'base': [1,1,1,1,1],
+    'floats': [1.1,1.1,1.1,1.2,0.9],
+    'decimals': [Decimal('1.1'), Decimal('1.1'), Decimal('1.1'), Decimal('1.1'), Decimal('1.1')],
+    'null_floats': [np.nan, 1.1, 1, 1, 1],
+    'strings': ['1', '1', '1', '1.1', '1'],
+    'mixed_strings': ['1','1','1','2','some string'],
+    'infinity': [1,1,1,1,np.inf]
+    })
+
+@pytest.mark.parametrize('column,expected', [
+    ('base', 0),
+    ('floats', 0.2),
+    ('decimals', 0.1),
+    ('null_floats', 0.1),
+    ('strings', 0.1),
+    ('mixed_strings', 0),
+    ('infinity', np.inf)
+])
+def test_calculate_max_diff(column, expected):
+    assert np.isclose(datacompy.calculate_max_diff(MAX_DIFF_DF['base'], MAX_DIFF_DF[column]), expected)

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
-e git+https://github.com/capitalone/datacompy.git@4aae55019a72c527ec043e417faae9b40b3bf29b#egg=datacompy
importlib-metadata==4.8.3
iniconfig==1.1.1
numpy==1.19.5
packaging==21.3
pandas==0.23.1
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
python-dateutil==2.9.0.post0
pytz==2025.2
six==1.17.0
tomli==1.2.3
typing_extensions==4.1.1
zipp==3.6.0

name: datacompy
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - numpy==1.19.5
      - packaging==21.3
      - pandas==0.23.1
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - six==1.17.0
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - zipp==3.6.0
prefix: /opt/conda/envs/datacompy

tests/test_core.py::test_calculate_max_diff[base-0] tests/test_core.py::test_calculate_max_diff[floats-0.2] tests/test_core.py::test_calculate_max_diff[decimals-0.1] tests/test_core.py::test_calculate_max_diff[null_floats-0.1] tests/test_core.py::test_calculate_max_diff[strings-0.1] tests/test_core.py::test_calculate_max_diff[mixed_strings-0] tests/test_core.py::test_calculate_max_diff[infinity-inf]
tests/test_core.py::test_compare_df_setter_bad tests/test_core.py::test_compare_df_setter_bad_index tests/test_core.py::test_compare_on_index_and_join_columns
tests/test_core.py::test_numeric_columns_equal_abs tests/test_core.py::test_numeric_columns_equal_rel tests/test_core.py::test_string_columns_equal tests/test_core.py::test_string_columns_equal_with_ignore_spaces tests/test_core.py::test_date_columns_equal tests/test_core.py::test_date_columns_equal_with_ignore_spaces tests/test_core.py::test_date_columns_unequal tests/test_core.py::test_bad_date_columns tests/test_core.py::test_rounded_date_columns tests/test_core.py::test_decimal_float_columns_equal tests/test_core.py::test_decimal_float_columns_equal_rel tests/test_core.py::test_decimal_columns_equal tests/test_core.py::test_decimal_columns_equal_rel tests/test_core.py::test_infinity_and_beyond tests/test_core.py::test_mixed_column tests/test_core.py::test_mixed_column_with_ignore_spaces tests/test_core.py::test_compare_df_setter_good tests/test_core.py::test_compare_df_setter_different_cases tests/test_core.py::test_compare_df_setter_good_index tests/test_core.py::test_columns_overlap tests/test_core.py::test_columns_no_overlap tests/test_core.py::test_10k_rows tests/test_core.py::test_subset tests/test_core.py::test_not_subset tests/test_core.py::test_large_subset tests/test_core.py::test_string_joiner tests/test_core.py::test_decimal_with_joins tests/test_core.py::test_decimal_with_nulls tests/test_core.py::test_strings_with_joins tests/test_core.py::test_index_joining tests/test_core.py::test_index_joining_strings_i_guess tests/test_core.py::test_index_joining_non_overlapping tests/test_core.py::test_temp_column_name tests/test_core.py::test_temp_column_name_one_has tests/test_core.py::test_temp_column_name_both_have tests/test_core.py::test_temp_column_name_one_already tests/test_core.py::test_simple_dupes_one_field tests/test_core.py::test_simple_dupes_two_fields tests/test_core.py::test_simple_dupes_index tests/test_core.py::test_simple_dupes_one_field_two_vals tests/test_core.py::test_simple_dupes_one_field_three_to_two_vals tests/test_core.py::test_dupes_from_real_data tests/test_core.py::test_strings_with_joins_with_ignore_spaces tests/test_core.py::test_decimal_with_joins_with_ignore_spaces tests/test_core.py::test_index_with_joins_with_ignore_spaces
.gitignore datacompy/core.py
.gitignore datacompy/core.py