Skip to content

Commit bf06212

Browse files
Fix tests for pandas >= 2.0.0 (#3456)
Fix datatable when tested with the new [pandas 2.0.0](https://pandas.pydata.org/docs/dev/whatsnew/v2.0.0.html).
1 parent 1911f0a commit bf06212

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
@pytest.fixture(autouse=True, scope="session")
3838
def setup():
3939
"""This fixture will be run once only."""
40-
assert sys.version_info >= (3, 6), "Python version 3.6+ is required"
40+
assert sys.version_info >= (3, 8), "Python version 3.8+ is required"
4141
dt.options.progress.enabled = False
4242

4343

@@ -111,6 +111,7 @@ def pandas():
111111
with warnings.catch_warnings():
112112
warnings.simplefilter("ignore")
113113
import pandas as pd
114+
pd.__major_version__ = int(pd.__version__.split(".")[0])
114115
return pd
115116
except ImportError:
116117
pytest.skip("Pandas module is required for this test")

tests/frame/test-to-pandas.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
#-------------------------------------------------------------------------------
4-
# Copyright 2018-2021 H2O.ai
4+
# Copyright 2018-2023 H2O.ai
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a
77
# copy of this software and associated documentation files (the "Software"),
@@ -120,7 +120,8 @@ def test_topandas_keyed(pd):
120120
assert list(pf.columns) == ["B", "R"]
121121
assert pf['B'].tolist() == [7, 14, 1, 0]
122122
assert pf['R'].tolist() == ['va', 'dfkjv', 'q', '...']
123-
assert isinstance(pf.index, pd.core.indexes.numeric.Int64Index)
123+
assert isinstance(pf.index, pd.Index)
124+
assert pd.api.types.is_numeric_dtype(pf.index.dtype)
124125
assert pf.index.name == "A"
125126
assert pf.index.tolist() == [3, 5, 9, 11]
126127

tests/types/test-date32.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
#-------------------------------------------------------------------------------
4-
# Copyright 2021 H2O.ai
4+
# Copyright 2021-2023 H2O.ai
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a
77
# copy of this software and associated documentation files (the "Software"),
@@ -355,7 +355,10 @@ def test_date32_to_pandas(pd):
355355
pf = DT.to_pandas()
356356
assert pf.shape == (5, 1)
357357
assert list(pf.columns) == ['C0']
358-
assert pf['C0'].dtype.name == 'datetime64[ns]'
358+
# For pandas >= 2.0.0 dates are stored as `datetime64[s]`,
359+
# in contrast to the older pandas, where they are `datetime64[ns]`.
360+
pf_dtype = 'datetime64[s]' if pd.__major_version__ > 1 else 'datetime64[ns]'
361+
assert pf['C0'].dtype.name == pf_dtype
359362
assert pf['C0'].to_list() == [
360363
pd.Timestamp(2000, 1, 1),
361364
pd.Timestamp(2005, 7, 12),

0 commit comments

Comments
 (0)