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

Compat: pandas MultiIndex .labels to .codes #103

Merged
merged 3 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion recordlinkage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions recordlinkage/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import warnings
from functools import wraps
from packaging import version

import numpy

Expand Down Expand Up @@ -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"""
Expand Down
6 changes: 5 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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():
Expand Down