Skip to content

Commit

Permalink
Move functions to test modules to _utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
TheooJ committed Nov 21, 2023
1 parent b579028 commit 45b3af9
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 19 deletions.
13 changes: 0 additions & 13 deletions skrub/_dataframe/_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ def is_polars(dataframe):
return isinstance(dataframe, (pl.DataFrame, pl.LazyFrame))


def is_namespace_pandas(px):
return px is pd


def is_namespace_polars(px):
if "polars" not in sys.modules:
return False

import polars as pl

return px is pl


def get_df_namespace(*dfs):
"""Get the namespaces of dataframes.
Expand Down
8 changes: 8 additions & 0 deletions skrub/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@ def atleast_2d_or_none(x):

def clone_if_default(estimator, default_estimator):
return clone(estimator) if estimator is default_estimator else estimator


def is_namespace_pandas(px):
return px.__name__ == "pandas"


def is_namespace_polars(px):
return px.__name__ == "polars"
2 changes: 1 addition & 1 deletion skrub/tests/test_datetime_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from numpy.testing import assert_allclose, assert_array_equal
from pandas.testing import assert_frame_equal

from skrub._dataframe._namespace import is_namespace_polars
from skrub._dataframe._polars import POLARS_SETUP
from skrub._datetime_encoder import (
TIME_LEVELS,
DatetimeEncoder,
_is_pandas_format_mixed_available,
to_datetime,
)
from skrub._utils import is_namespace_polars

MODULES = [pd]
ASSERT_TUPLES = [(pd, assert_frame_equal)]
Expand Down
2 changes: 1 addition & 1 deletion skrub/tests/test_fuzzy_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from sklearn.feature_extraction.text import HashingVectorizer

from skrub import fuzzy_join
from skrub._dataframe._namespace import is_namespace_polars
from skrub._dataframe._polars import POLARS_SETUP
from skrub._utils import is_namespace_polars

MODULES = [pd]
ASSERT_TUPLES = [(pd, assert_frame_equal)]
Expand Down
2 changes: 1 addition & 1 deletion skrub/tests/test_gap_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from sklearn.model_selection import train_test_split

from skrub import GapEncoder
from skrub._dataframe._namespace import is_namespace_polars
from skrub._dataframe._polars import POLARS_SETUP
from skrub._utils import is_namespace_polars
from skrub.datasets import fetch_midwest_survey
from skrub.tests.utils import generate_data

Expand Down
2 changes: 1 addition & 1 deletion skrub/tests/test_interpolation_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from sklearn.neighbors import KNeighborsClassifier, KNeighborsRegressor

from skrub import InterpolationJoiner
from skrub._dataframe._namespace import is_namespace_polars
from skrub._dataframe._polars import POLARS_SETUP
from skrub._utils import is_namespace_polars

MODULES = [pd]

Expand Down
2 changes: 1 addition & 1 deletion skrub/tests/test_joiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pandas.testing import assert_frame_equal

from skrub import Joiner
from skrub._dataframe._namespace import is_namespace_polars
from skrub._dataframe._polars import POLARS_SETUP
from skrub._utils import is_namespace_polars

MODULES = [pd]
ASSERT_TUPLES = [(pd, assert_frame_equal)]
Expand Down
2 changes: 1 addition & 1 deletion skrub/tests/test_similarity_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from sklearn.exceptions import NotFittedError

from skrub import SimilarityEncoder
from skrub._dataframe._namespace import is_namespace_polars
from skrub._dataframe._polars import POLARS_SETUP
from skrub._similarity_encoder import ngram_similarity_matrix
from skrub._string_distances import ngram_similarity
from skrub._utils import is_namespace_polars

MODULES = [pd]
INPUT_TYPES = ["list", "numpy", "pandas"]
Expand Down

0 comments on commit 45b3af9

Please sign in to comment.