From b96a37469f4548d2e238b8527c55f86b0b0064c4 Mon Sep 17 00:00:00 2001 From: William Ayd Date: Sat, 26 Mar 2022 08:48:58 -0700 Subject: [PATCH] Cleanup old compat (#148) --- pantab/_compat.py | 1 - pantab/_types.py | 28 +++++++++------------------- pantab/tests/conftest.py | 5 ++--- pantab/tests/test_reader.py | 9 ++------- pantab/tests/test_roundtrip.py | 6 ++---- setup.py | 2 +- 6 files changed, 16 insertions(+), 35 deletions(-) diff --git a/pantab/_compat.py b/pantab/_compat.py index 62b160f4..384c63c4 100644 --- a/pantab/_compat.py +++ b/pantab/_compat.py @@ -2,7 +2,6 @@ import pandas as pd -PANDAS_100 = LooseVersion(pd.__version__) >= LooseVersion("1.0.0") PANDAS_120 = LooseVersion(pd.__version__) >= LooseVersion("1.2.0") PANDAS_130 = LooseVersion(pd.__version__) >= LooseVersion("1.3.0") diff --git a/pantab/_types.py b/pantab/_types.py index 93f496f4..b694407e 100644 --- a/pantab/_types.py +++ b/pantab/_types.py @@ -33,17 +33,12 @@ "object": _ColumnType(tab_api.SqlType.text(), tab_api.Nullability.NULLABLE), } -if compat.PANDAS_100: - _column_types["string"] = _ColumnType( - tab_api.SqlType.text(), tab_api.Nullability.NULLABLE - ) - _column_types["boolean"] = _ColumnType( - tab_api.SqlType.bool(), tab_api.Nullability.NULLABLE - ) -else: - _column_types["object"] = _ColumnType( - tab_api.SqlType.text(), tab_api.Nullability.NULLABLE - ) +_column_types["string"] = _ColumnType( + tab_api.SqlType.text(), tab_api.Nullability.NULLABLE +) +_column_types["boolean"] = _ColumnType( + tab_api.SqlType.bool(), tab_api.Nullability.NULLABLE +) if compat.PANDAS_120: _column_types["Float32"] = _ColumnType( @@ -64,11 +59,6 @@ _pandas_types[ _ColumnType(tab_api.SqlType.double(), tab_api.Nullability.NOT_NULLABLE) ] = "float64" -if compat.PANDAS_100: - _pandas_types[ - _ColumnType(tab_api.SqlType.text(), tab_api.Nullability.NOT_NULLABLE) - ] = "string" -else: - _pandas_types[ - _ColumnType(tab_api.SqlType.text(), tab_api.Nullability.NOT_NULLABLE) - ] = "object" +_pandas_types[ + _ColumnType(tab_api.SqlType.text(), tab_api.Nullability.NOT_NULLABLE) +] = "string" diff --git a/pantab/tests/conftest.py b/pantab/tests/conftest.py index 7de67e81..cf5a06c1 100644 --- a/pantab/tests/conftest.py +++ b/pantab/tests/conftest.py @@ -124,9 +124,8 @@ def df(): } ) - if compat.PANDAS_100: - df["boolean"] = pd.Series([True, False, pd.NA], dtype="boolean") - df["string"] = pd.Series(["foo", "bar", pd.NA], dtype="string") + df["boolean"] = pd.Series([True, False, pd.NA], dtype="boolean") + df["string"] = pd.Series(["foo", "bar", pd.NA], dtype="string") if compat.PANDAS_120: df["Float32"] = pd.Series([1.0, 2.0, pd.NA], dtype="Float32") diff --git a/pantab/tests/test_reader.py b/pantab/tests/test_reader.py index e68cdef8..03dc2991 100644 --- a/pantab/tests/test_reader.py +++ b/pantab/tests/test_reader.py @@ -4,7 +4,6 @@ from tableauhyperapi import TableName import pantab -import pantab._compat as compat def test_read_doesnt_modify_existing_file(df, tmp_hyper): @@ -97,10 +96,7 @@ def test_reads_non_writeable(datapath): [["row1", 1.0], ["row2", 2.0]], columns=["Non-Nullable String", "Non-Nullable Float"], ) - if compat.PANDAS_100: - expected["Non-Nullable String"] = expected["Non-Nullable String"].astype( - "string" - ) + expected["Non-Nullable String"] = expected["Non-Nullable String"].astype("string") tm.assert_frame_equal(result, expected) @@ -112,7 +108,6 @@ def test_read_query(df, tmp_hyper): result = pantab.frame_from_hyper_query(tmp_hyper, query) expected = pd.DataFrame([[1, "_2"], [6, "_7"], [0, "_0"]], columns=["i", "_i2"]) - str_type = "string" if compat.PANDAS_100 else "object" - expected = expected.astype({"i": "Int16", "_i2": str_type}) + expected = expected.astype({"i": "Int16", "_i2": "string"}) tm.assert_frame_equal(result, expected) diff --git a/pantab/tests/test_roundtrip.py b/pantab/tests/test_roundtrip.py index ff53b583..749b5444 100644 --- a/pantab/tests/test_roundtrip.py +++ b/pantab/tests/test_roundtrip.py @@ -7,15 +7,13 @@ from tableauhyperapi import Connection, CreateMode, HyperProcess, TableName, Telemetry import pantab -import pantab._compat as compat def assert_roundtrip_equal(result, expected): """Compat helper for comparing round-tripped results.""" - if compat.PANDAS_100: - expected["object"] = expected["object"].astype("string") - expected["non-ascii"] = expected["non-ascii"].astype("string") + expected["object"] = expected["object"].astype("string") + expected["non-ascii"] = expected["non-ascii"].astype("string") tm.assert_frame_equal(result, expected) diff --git a/setup.py b/setup.py index a78eab26..db13567e 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,7 @@ package_data={"": ["*.h"], "pantab.tests": ["data/*"]}, data_files=[("", ["LICENSE.txt", "README.md"])], python_requires=">=3.8", - install_requires=["pandas", "tableauhyperapi", "numpy"], + install_requires=["pandas>=1.0.0", "tableauhyperapi", "numpy"], extras_require={"dev": ["pytest"]}, ext_modules=[pantab_module], )