Skip to content

Commit

Permalink
Cleanup old compat (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd authored Mar 26, 2022
1 parent 38b05d2 commit b96a374
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 35 deletions.
1 change: 0 additions & 1 deletion pantab/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
28 changes: 9 additions & 19 deletions pantab/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
5 changes: 2 additions & 3 deletions pantab/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 2 additions & 7 deletions pantab/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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)
6 changes: 2 additions & 4 deletions pantab/tests/test_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
)

0 comments on commit b96a374

Please sign in to comment.