Skip to content

Commit 22a100d

Browse files
committed
pandas version-dependent map or applymap
It seems the transition from `applymap` to `map` is <1 year old, starting pandas version 2.1: https://pandas.pydata.org/pandas-docs/version/2.1/reference/api/pandas.DataFrame.map.html This is too new to fully rely on. Especially when it breaks for python 3.7 and 3.8 that are not supported by newer pandas versions, which I'm not yet comfortable with (although their end-of-life status, because I'm not sure how causallib supports 3.12 at the moment). So putting a pandas version-dependent choice makes sense at the moment and can later be discarded. Signed-off-by: Ehud-Karavani <[email protected]>
1 parent 0ce5dfc commit 22a100d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

causallib/tests/test_matching.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,20 @@ def test_classify_task(self):
542542
ypred = self.matching.estimate_individual_outcome(
543543
X, a, predict_proba=False)
544544
# if not all integers will raise errors
545-
ypred.map(str).map(int)
546-
with self.assertRaises(ValueError):
547-
self.matching.estimate_individual_outcome(
548-
X, a, predict_proba=True
549-
).map(str).map(int)
545+
if pd.__version__ > "2.1":
546+
# TODO: at time of writing pandas 2.1.0 is <1 year old.
547+
# Once matured, you may erase the deprecated `applymap` and just use `map`.
548+
ypred.map(str).map(int)
549+
with self.assertRaises(ValueError):
550+
self.matching.estimate_individual_outcome(
551+
X, a, predict_proba=True
552+
).map(str).map(int)
553+
else:
554+
ypred.applymap(str).applymap(int)
555+
with self.assertRaises(ValueError):
556+
self.matching.estimate_individual_outcome(
557+
X, a, predict_proba=True
558+
).applymap(str).applymap(int)
550559

551560
def test_classify_task_with_wrong_inputs_warning_check(self):
552561
X, a, y = self.data_3feature_linear_effect

0 commit comments

Comments
 (0)