diff --git a/recordlinkage/base.py b/recordlinkage/base.py index ec3bab6d..23590ca1 100644 --- a/recordlinkage/base.py +++ b/recordlinkage/base.py @@ -285,7 +285,11 @@ def _dedup_index(self, df_a): # Remove all pairs not in the lower triangular part of the matrix. # This part can be inproved by not comparing the level values, but the # level itself. - pairs = pairs[pairs.labels[0] > pairs.labels[1]] + try: + pairs = pairs[pairs.codes[0] > pairs.codes[1]] + except AttributeError: + # backwards compat pandas <24 + pairs = pairs[pairs.labels[0] > pairs.labels[1]] return pairs diff --git a/recordlinkage/utils.py b/recordlinkage/utils.py index c25917a8..bfbce959 100644 --- a/recordlinkage/utils.py +++ b/recordlinkage/utils.py @@ -1,5 +1,6 @@ import warnings from functools import wraps +from packaging import version import numpy @@ -77,6 +78,10 @@ def func_wrapper(*args, **kwargs): # Checks and conversions +def is_min_pandas_version(min_version): + """Check if pandas version is larger or equal the version passed.""" + return version.parse(pandas.__version__) >= version.parse(min_version) + def is_label_dataframe(label, df): """check column label existance""" diff --git a/tests/test_misc.py b/tests/test_misc.py index 52865008..b6c5c966 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -10,6 +10,7 @@ import recordlinkage as rl from recordlinkage import index_split +from recordlinkage.utils import is_min_pandas_version def test_multiindex_split(): @@ -24,7 +25,10 @@ def test_multiindex_split(): ptm.assert_index_equal(result_index_chunk, expected_index_chunk) assert len(result_index_chunk.levels) == 2 - assert len(result_index_chunk.labels) == 2 + if is_min_pandas_version("0.24.0"): + assert len(result_index_chunk.codes) == 2 + else: + assert len(result_index_chunk.labels) == 2 def test_options():