Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Adapt tests to pandas 2.1 and fix deprecations #6560

Merged
merged 5 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9

- name: Install Tox
run: |
Expand All @@ -37,20 +37,20 @@ jobs:
fail-fast: False
matrix:
os: [ubuntu-22.04]
python-version: [3.8, 3.9, '3.10', '3.11']
python-version: [3.9, '3.10', '3.11']
tox_env: [orange-released]
name: [Released]
include:
- os: ubuntu-22.04
python-version: '3.10'
python-version: '3.11'
tox_env: orange-latest
name: Latest
- os: ubuntu-20.04
python-version: 3.8
python-version: 3.9
tox_env: orange-oldest
name: Oldest dependencies
- os: ubuntu-22.04
python-version: 3.9
python-version: '3.10'
tox_env: pyqt6
name: PyQt6

Expand Down Expand Up @@ -120,16 +120,16 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
python-version: [3.8, 3.9, '3.10', '3.11']
python-version: [3.9, '3.10', '3.11']
tox_env: [orange-released]
name: [Released]
include:
- os: windows-latest
python-version: '3.10'
python-version: '3.11'
tox_env: orange-latest
name: Latest
- os: macos-latest
python-version: '3.10'
python-version: '3.11'
tox_env: orange-latest
name: Latest
- os: windows-latest
Expand Down
17 changes: 10 additions & 7 deletions Orange/data/pandas_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from unittest.mock import patch

import numpy as np
from pandas import SparseDtype
from scipy import sparse as sp
from scipy.sparse import csr_matrix
import pandas as pd
from pandas.core.arrays import SparseArray
from pandas.api.types import (
is_categorical_dtype, is_object_dtype,
is_datetime64_any_dtype, is_numeric_dtype, is_integer_dtype
is_object_dtype,
is_datetime64_any_dtype,
is_numeric_dtype,
is_integer_dtype,
)

from Orange.data import (
Expand Down Expand Up @@ -166,9 +167,11 @@ def _reset_index(df: pd.DataFrame) -> pd.DataFrame:


def _is_discrete(s, force_nominal):
return (is_categorical_dtype(s) or
is_object_dtype(s) and (force_nominal or
s.nunique() < s.size ** .666))
return (
isinstance(s.dtype, pd.CategoricalDtype)
or is_object_dtype(s)
and (force_nominal or s.nunique() < s.size**0.666)
)


def _is_datetime(s):
Expand Down Expand Up @@ -297,7 +300,7 @@ def vars_from_df(df, role=None, force_nominal=False):
elif not any(a_expr):
# if all c in columns table will share memory with dataframe
a_df = df if all(c in a_cols for c in df.columns) else df[a_cols]
if all(isinstance(a, SparseDtype) for a in a_df.dtypes):
if all(isinstance(a, pd.SparseDtype) for a in a_df.dtypes):
arr = csr_matrix(a_df.sparse.to_coo())
else:
arr = np.asarray(a_df)
Expand Down
15 changes: 12 additions & 3 deletions Orange/data/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ def test_table_from_frame_date(self):
self.assertEqual(table.domain.variables[0].have_time, 0)
self.assertEqual(table.domain.variables[0].have_date, 1)

@skipIf(
pd.__version__.split(".")[:2] == ["2", "0"],
"Skipping because of pandas issue in version 2.0.*",
)
# https://github.com/pandas-dev/pandas/issues/53134#issuecomment-1546011517
def test_table_from_frame_time(self):
df = pd.DataFrame(
[[pd.Timestamp("00:00:00.25")], [pd.Timestamp("20:20:20.30")], [np.nan]]
Expand Down Expand Up @@ -414,15 +419,19 @@ def testa_table_from_frame_string(self):
self.assertTrue(all(isinstance(v, StringVariable) for v in table.domain.metas))

@skipIf(
datetime.today() < datetime(2023, 10, 1),
"Temporarily skipping because of pandas issue",
pd.__version__.split(".")[:2] == ["2", "0"],
"Skipping because of pandas issue in version 2.0.*",
)
# https://github.com/pandas-dev/pandas/issues/53134#issuecomment-1546011517
def test_time_variable_compatible(self):
def to_df(val):
return pd.DataFrame([[pd.Timestamp(val)]])

for datestr, timestamp, outstr in TestTimeVariable.TESTS:
if datestr == "010101.01":
# 010101.01 parses as Jan 1 year 1 which isn't wrong since we do
# not provide format (and pandas does as it does in this case)
continue
var = TimeVariable("time")
var_parse = var.to_val(datestr)
try:
Expand Down Expand Up @@ -786,7 +795,7 @@ def test_to_dfs(self):
def test_amend(self):
with self.table.unlocked():
df = self.table.X_df
df.iloc[0][0] = 0
df.iloc[0, 0] = 0
X = self.table.X
with self.table.unlocked():
self.table.X_df = df
Expand Down
2 changes: 1 addition & 1 deletion conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ requirements:
- recommonmark
run:
- python
- setuptools >=41.0.0
- setuptools >=51.0.0
- numpy >=1.20.0
- scipy >=1.9
- scikit-learn >=1.1.0,<1.2.0
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = [
"setuptools>=41.0.0,<50.0",
"setuptools>=51.0",
"wheel",
"cython>=3.0",
"oldest-supported-numpy",
Expand Down
2 changes: 1 addition & 1 deletion requirements-core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ chardet>=3.0.2
joblib>=1.0.0
keyring
keyrings.alt # for alternative keyring implementations
setuptools>=41.0.0
setuptools>=51.0.0
serverfiles # for Data Sets synchronization
networkx
python-louvain>=0.13
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ deps =
oldest: joblib==1.0.0
# oldest: keyring
# oldest: keyrings.alt
oldest: setuptools==41.0.0
oldest: setuptools==51.0.0
# oldest: serverfiles
# oldest: networkx
oldest: python-louvain==0.13
Expand Down