Skip to content

Commit

Permalink
Remove use of LooseVersion and hide get_renderer warning (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnothman authored Dec 28, 2023
1 parent 47b2f90 commit 0f308e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
11 changes: 2 additions & 9 deletions upsetplot/data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import print_function, division, absolute_import
from numbers import Number
import functools
from distutils.version import LooseVersion
import warnings

import pandas as pd
Expand Down Expand Up @@ -385,12 +383,7 @@ def from_contents(contents, data=None, id_column="id"):
if not all(s.index.is_unique for s in cat_series):
raise ValueError("Got duplicate ids in a category")

concat = pd.concat
if LooseVersion(pd.__version__) >= "0.23.0":
# silence the warning
concat = functools.partial(concat, sort=False)

df = concat(cat_series, axis=1)
df = pd.concat(cat_series, axis=1, sort=False)
if id_column in df.columns:
raise ValueError("A category cannot be named %r" % id_column)
df.fillna(False, inplace=True)
Expand All @@ -408,6 +401,6 @@ def from_contents(contents, data=None, id_column="id"):
"data: %r" % not_in_data.index.values
)
df = df.reindex(index=data.index).fillna(False)
df = concat([data, df], axis=1)
df = pd.concat([data, df], axis=1, sort=False)
df.index.name = id_column
return df.reset_index().set_index(cat_names)
9 changes: 7 additions & 2 deletions upsetplot/plotting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import print_function, division, absolute_import

import typing
import warnings

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -648,13 +649,17 @@ def make_grid(self, fig=None):
)
window_extent_args = {}
if RENDERER_IMPORTED:
window_extent_args["renderer"] = get_renderer(fig)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
window_extent_args["renderer"] = get_renderer(fig)
textw = t.get_window_extent(**window_extent_args).width
t.remove()

window_extent_args = {}
if RENDERER_IMPORTED:
window_extent_args["renderer"] = get_renderer(fig)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
window_extent_args["renderer"] = get_renderer(fig)
figw = self._reorient(fig.get_window_extent(**window_extent_args)).width

sizes = np.asarray([p["elements"] for p in self._subset_plots])
Expand Down
4 changes: 1 addition & 3 deletions upsetplot/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pytest
import pandas as pd
import numpy as np
from distutils.version import LooseVersion
from pandas.testing import assert_series_equal, assert_frame_equal, assert_index_equal
from upsetplot import from_memberships, from_contents, from_indicators, generate_data

Expand Down Expand Up @@ -71,8 +70,7 @@ def test_from_memberships_with_data(data, ndim):
assert out is not data # make sure frame is copied
if hasattr(data, "loc") and np.asarray(data).dtype.kind in "ifb":
# but not deepcopied when possible
if LooseVersion(pd.__version__) > LooseVersion("0.35"):
assert out.values.base is np.asarray(data).base
assert out.values.base is np.asarray(data).base
if ndim == 1:
assert isinstance(out, pd.Series)
else:
Expand Down

0 comments on commit 0f308e7

Please sign in to comment.