Skip to content

Commit

Permalink
Make timestamp test pandas version aware
Browse files Browse the repository at this point in the history
Pandas >= 2.1.0 uses [us] instead of [ns] for timestamp objects.
  • Loading branch information
parejkoj committed Sep 1, 2023
1 parent 5c27103 commit 80dc857
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
import unittest
import yaml

# These three imports are to check the pandas version.
import importlib.metadata
import pandas # noqa: F401
import packaging.version

from lsst.daf.butler import Butler
import lsst.utils.tests

Expand Down Expand Up @@ -56,14 +61,18 @@ def _validateSchema(self, dataset, dataId, tableName):
outputColumnNames = set(df.columns.to_list())
self.assertEqual(outputColumnNames, set(expectedColumns.keys()), f"{info} failed")

# the data type mapping from felis datatype to pandas
# Pandas 2.1.0 changed the datetime dtype from [ns] -> [us],
# so we need a pandas version-aware test here.
pdVersion = packaging.version.parse(importlib.metadata.version("pandas"))
pdChanged = packaging.version.Version('2.1.0')
# Check the data type mapping from felis datatype to pandas.
typeMapping = {"boolean": "bool",
"int": "int32",
"long": "int64",
"float": "float32",
"double": "float64",
"char": "object",
"timestamp": "datetime64[ns]"}
"timestamp": "datetime64[us]" if pdVersion >= pdChanged else "datetime64[ns]"}
for column in outputColumnNames:
self.assertEqual(df.dtypes.get(column).name,
typeMapping[expectedColumns[column]],
Expand Down

0 comments on commit 80dc857

Please sign in to comment.