From 23eb68587291d3d47fead34749dde1fc884b90f7 Mon Sep 17 00:00:00 2001 From: Stefan Krawczyk Date: Thu, 22 Sep 2022 12:22:55 -0700 Subject: [PATCH] Adds time index type check compatible with py3.6 Pandas dropped support for python 3.6 in something like 1.2. So pandas 1.1.5 is what we're using in our CI system, and that does not have the `NDArrayBackedExtensionIndex` type. So I'm guessing here, but looking at the 1.1.5 source, we instead want `ExtensionIndex`. --- hamilton/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hamilton/base.py b/hamilton/base.py index 2c43df77..1b30a428 100644 --- a/hamilton/base.py +++ b/hamilton/base.py @@ -64,7 +64,11 @@ def pandas_index_types( for output_name, output_value in outputs.items(): if isinstance(output_value, (pd.DataFrame, pd.Series)): dict_key = f"{output_value.index.__class__.__name__}:::{output_value.index.dtype}" - if isinstance(output_value.index, pd_extension.NDArrayBackedExtensionIndex): + try: + index_type = getattr(pd_extension, "NDArrayBackedExtensionIndex") + except AttributeError: # for python 3.6 & pandas 1.1.5 + index_type = getattr(pd_extension, "ExtensionIndex") + if isinstance(output_value.index, index_type): # it's a time index -- these will produce garbage if not aligned properly. time_indexes[dict_key].append(output_name) else: