Skip to content

Explicit LooseVersion comps #18637

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

Merged
merged 1 commit into from
Dec 6, 2017
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
4 changes: 2 additions & 2 deletions pandas/_libs/sparse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ from distutils.version import LooseVersion

# numpy versioning
_np_version = np.version.short_version
_np_version_under1p10 = LooseVersion(_np_version) < '1.10'
_np_version_under1p11 = LooseVersion(_np_version) < '1.11'
_np_version_under1p10 = LooseVersion(_np_version) < LooseVersion('1.10')
_np_version_under1p11 = LooseVersion(_np_version) < LooseVersion('1.11')

np.import_array()
np.import_ufunc()
Expand Down
2 changes: 1 addition & 1 deletion pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def raise_with_traceback(exc, traceback=Ellipsis):
# dateutil minimum version
import dateutil

if LooseVersion(dateutil.__version__) < '2.5':
if LooseVersion(dateutil.__version__) < LooseVersion('2.5'):
raise ImportError('dateutil 2.5.0 is the minimum required version')
from dateutil import parser as _date_parser
parse_date = _date_parser.parse
Expand Down
12 changes: 6 additions & 6 deletions pandas/compat/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
# numpy versioning
_np_version = np.__version__
_nlv = LooseVersion(_np_version)
_np_version_under1p10 = _nlv < '1.10'
_np_version_under1p11 = _nlv < '1.11'
_np_version_under1p12 = _nlv < '1.12'
_np_version_under1p13 = _nlv < '1.13'
_np_version_under1p14 = _nlv < '1.14'
_np_version_under1p15 = _nlv < '1.15'
_np_version_under1p10 = _nlv < LooseVersion('1.10')
_np_version_under1p11 = _nlv < LooseVersion('1.11')
_np_version_under1p12 = _nlv < LooseVersion('1.12')
_np_version_under1p13 = _nlv < LooseVersion('1.13')
_np_version_under1p14 = _nlv < LooseVersion('1.14')
_np_version_under1p15 = _nlv < LooseVersion('1.15')

if _nlv < '1.9':
raise ImportError('this version of pandas is incompatible with '
Expand Down
4 changes: 2 additions & 2 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def ip():


is_dateutil_le_261 = pytest.mark.skipif(
LooseVersion(dateutil.__version__) > '2.6.1',
LooseVersion(dateutil.__version__) > LooseVersion('2.6.1'),
reason="dateutil api change version")
is_dateutil_gt_261 = pytest.mark.skipif(
LooseVersion(dateutil.__version__) <= '2.6.1',
LooseVersion(dateutil.__version__) <= LooseVersion('2.6.1'),
reason="dateutil stable version")
2 changes: 1 addition & 1 deletion pandas/core/computation/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

try:
import numexpr as ne
ver = ne.__version__
ver = LooseVersion(ne.__version__)
_NUMEXPR_INSTALLED = ver >= LooseVersion(_MIN_NUMEXPR_VERSION)

if not _NUMEXPR_INSTALLED:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def _from_derivatives(xi, yi, x, order=None, der=0, extrapolate=False):
import scipy
from scipy import interpolate

if LooseVersion(scipy.__version__) < '0.18.0':
if LooseVersion(scipy.__version__) < LooseVersion('0.18.0'):
try:
method = interpolate.piecewise_polynomial_interpolate
return method(xi, yi.reshape(-1, 1), x,
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/feather_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _try_import():
"pip install -U feather-format\n")

try:
feather.__version__ >= LooseVersion('0.3.1')
LooseVersion(feather.__version__) >= LooseVersion('0.3.1')
except AttributeError:
raise ImportError("the feather-format library must be >= "
"version 0.3.1\n"
Expand Down Expand Up @@ -106,7 +106,7 @@ def read_feather(path, nthreads=1):
feather = _try_import()
path = _stringify_path(path)

if feather.__version__ < LooseVersion('0.4.0'):
if LooseVersion(feather.__version__) < LooseVersion('0.4.0'):
return feather.read_dataframe(path)

return feather.read_dataframe(path, nthreads=nthreads)
2 changes: 1 addition & 1 deletion pandas/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def _parser_dispatch(flavor):
raise ImportError(
"BeautifulSoup4 (bs4) not found, please install it")
import bs4
if bs4.__version__ == LooseVersion('4.2.0'):
if LooseVersion(bs4.__version__) == LooseVersion('4.2.0'):
raise ValueError("You're using a version"
" of BeautifulSoup4 (4.2.0) that has been"
" known to cause problems on certain"
Expand Down
10 changes: 6 additions & 4 deletions pandas/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ def __init__(self):
"\nor via pip\n"
"pip install -U pyarrow\n")

if LooseVersion(pyarrow.__version__) < '0.4.1':
if LooseVersion(pyarrow.__version__) < LooseVersion('0.4.1'):
raise ImportError("pyarrow >= 0.4.1 is required for parquet"
"support\n\n"
"you can install via conda\n"
"conda install pyarrow -c conda-forge\n"
"\nor via pip\n"
"pip install -U pyarrow\n")

self._pyarrow_lt_050 = LooseVersion(pyarrow.__version__) < '0.5.0'
self._pyarrow_lt_060 = LooseVersion(pyarrow.__version__) < '0.6.0'
self._pyarrow_lt_050 = (LooseVersion(pyarrow.__version__) <
LooseVersion('0.5.0'))
self._pyarrow_lt_060 = (LooseVersion(pyarrow.__version__) <
LooseVersion('0.6.0'))
self.api = pyarrow

def write(self, df, path, compression='snappy',
Expand Down Expand Up @@ -97,7 +99,7 @@ def __init__(self):
"\nor via pip\n"
"pip install -U fastparquet")

if LooseVersion(fastparquet.__version__) < '0.1.0':
if LooseVersion(fastparquet.__version__) < LooseVersion('0.1.0'):
raise ImportError("fastparquet >= 0.1.0 is required for parquet "
"support\n\n"
"you can install via conda\n"
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _tables():
_table_mod = tables

# version requirements
if LooseVersion(tables.__version__) < '3.0.0':
if LooseVersion(tables.__version__) < LooseVersion('3.0.0'):
raise ImportError("PyTables version >= 3.0.0 is required")

# set the file open policy
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def _is_sqlalchemy_connectable(con):
_SQLALCHEMY_INSTALLED = True

from distutils.version import LooseVersion
ver = LooseVersion(sqlalchemy.__version__)
ver = sqlalchemy.__version__
# For sqlalchemy versions < 0.8.2, the BIGINT type is recognized
# for a sqlite engine, which results in a warning when trying to
# read/write a DataFrame with int64 values. (GH7433)
if ver < '0.8.2':
if LooseVersion(ver) < LooseVersion('0.8.2'):
from sqlalchemy import BigInteger
from sqlalchemy.ext.compiler import compiles

Expand Down
21 changes: 11 additions & 10 deletions pandas/plotting/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def _mpl_le_1_2_1():
try:
import matplotlib as mpl
return (str(mpl.__version__) <= LooseVersion('1.2.1') and
return (LooseVersion(mpl.__version__) <= LooseVersion('1.2.1') and
str(mpl.__version__)[0] != '0')
except ImportError:
return False
Expand All @@ -19,34 +19,35 @@ def _mpl_ge_1_3_1():
import matplotlib
# The or v[0] == '0' is because their versioneer is
# messed up on dev
return (matplotlib.__version__ >= LooseVersion('1.3.1') or
matplotlib.__version__[0] == '0')
return (LooseVersion(matplotlib.__version__) >=
LooseVersion('1.3.1') or
str(matplotlib.__version__)[0] == '0')
except ImportError:
return False


def _mpl_ge_1_4_0():
try:
import matplotlib
return (matplotlib.__version__ >= LooseVersion('1.4') or
matplotlib.__version__[0] == '0')
return (LooseVersion(matplotlib.__version__) >= LooseVersion('1.4') or
str(matplotlib.__version__)[0] == '0')
except ImportError:
return False


def _mpl_ge_1_5_0():
try:
import matplotlib
return (matplotlib.__version__ >= LooseVersion('1.5') or
matplotlib.__version__[0] == '0')
return (LooseVersion(matplotlib.__version__) >= LooseVersion('1.5') or
str(matplotlib.__version__)[0] == '0')
except ImportError:
return False


def _mpl_ge_2_0_0():
try:
import matplotlib
return matplotlib.__version__ >= LooseVersion('2.0')
return LooseVersion(matplotlib.__version__) >= LooseVersion('2.0')
except ImportError:
return False

Expand All @@ -62,14 +63,14 @@ def _mpl_le_2_0_0():
def _mpl_ge_2_0_1():
try:
import matplotlib
return matplotlib.__version__ >= LooseVersion('2.0.1')
return LooseVersion(matplotlib.__version__) >= LooseVersion('2.0.1')
except ImportError:
return False


def _mpl_ge_2_1_0():
try:
import matplotlib
return matplotlib.__version__ >= LooseVersion('2.1')
return LooseVersion(matplotlib.__version__) >= LooseVersion('2.1')
except ImportError:
return False
5 changes: 3 additions & 2 deletions pandas/tests/computation/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_compat():
try:
import numexpr as ne
ver = ne.__version__
if ver < LooseVersion(_MIN_NUMEXPR_VERSION):
if LooseVersion(ver) < LooseVersion(_MIN_NUMEXPR_VERSION):
assert not _NUMEXPR_INSTALLED
else:
assert _NUMEXPR_INSTALLED
Expand All @@ -37,7 +37,8 @@ def testit():
except ImportError:
pytest.skip("no numexpr")
else:
if ne.__version__ < LooseVersion(_MIN_NUMEXPR_VERSION):
if (LooseVersion(ne.__version__) <
LooseVersion(_MIN_NUMEXPR_VERSION)):
with pytest.raises(ImportError):
testit()
else:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ def test_nan_to_nat_conversions():

# numpy < 1.7.0 is wrong
from distutils.version import LooseVersion
if LooseVersion(np.__version__) >= '1.7.0':
if LooseVersion(np.__version__) >= LooseVersion('1.7.0'):
assert (s[8].value == np.datetime64('NaT').astype(np.int64))


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ def test_round(self):
'col1': [1.123, 2.123, 3.123],
'col2': [1.2, 2.2, 3.2]})

if sys.version < LooseVersion('2.7'):
if LooseVersion(sys.version) < LooseVersion('2.7'):
# Rounding with decimal is a ValueError in Python < 2.7
with pytest.raises(ValueError):
df.round(nan_round_Series)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_itertuples(self):

tup = next(df.itertuples(name='TestName'))

if sys.version >= LooseVersion('2.7'):
if LooseVersion(sys.version) >= LooseVersion('2.7'):
assert tup._fields == ('Index', 'a', 'b')
assert (tup.Index, tup.a, tup.b) == tup
assert type(tup).__name__ == 'TestName'
Expand All @@ -231,7 +231,7 @@ def test_itertuples(self):
tup2 = next(df.itertuples(name='TestName'))
assert tup2 == (0, 1, 4)

if sys.version >= LooseVersion('2.7'):
if LooseVersion(sys.version) >= LooseVersion('2.7'):
assert tup2._fields == ('Index', '_1', '_2')

df3 = DataFrame({'f' + str(i): [i] for i in range(1024)})
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

try:
import scipy
_is_scipy_ge_0190 = scipy.__version__ >= LooseVersion('0.19.0')
_is_scipy_ge_0190 = (LooseVersion(scipy.__version__) >=
LooseVersion('0.19.0'))
except:
_is_scipy_ge_0190 = False

Expand Down Expand Up @@ -717,7 +718,7 @@ def test_interp_alt_scipy(self):
result = df.interpolate(method='pchip')
expected.loc[2, 'A'] = 3

if LooseVersion(scipy.__version__) >= '0.17.0':
if LooseVersion(scipy.__version__) >= LooseVersion('0.17.0'):
expected.loc[5, 'A'] = 6.0
else:
expected.loc[5, 'A'] = 6.125
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/frame/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ def test_rank_methods_frame(self):
sprank = sprank.astype(np.float64)
expected = DataFrame(sprank, columns=cols)

if LooseVersion(scipy.__version__) >= '0.17.0':
if (LooseVersion(scipy.__version__) >=
LooseVersion('0.17.0')):
expected = expected.astype('float64')
tm.assert_frame_equal(result, expected)

Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/generic/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def test_set_attribute(self):
assert_series_equal(df['y'], Series([2, 4, 6], name='y'))

@pytest.mark.skipif(not _XARRAY_INSTALLED or _XARRAY_INSTALLED and
LooseVersion(xarray.__version__) < '0.10.0',
LooseVersion(xarray.__version__) <
LooseVersion('0.10.0'),
reason='xarray >= 0.10.0 required')
@pytest.mark.parametrize(
"index", ['FloatIndex', 'IntIndex',
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/generic/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def finalize(self, other, method=None, **kwargs):
Series.__finalize__ = _finalize

@pytest.mark.skipif(not _XARRAY_INSTALLED or _XARRAY_INSTALLED and
LooseVersion(xarray.__version__) < '0.10.0',
LooseVersion(xarray.__version__) <
LooseVersion('0.10.0'),
reason='xarray >= 0.10.0 required')
@pytest.mark.parametrize(
"index",
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ def test_parsers_dayfirst_yearfirst(self, cache):
# 2.5.2 20/12/21 [dayfirst=1, yearfirst=0] -> 2021-12-20 00:00:00
# 2.5.3 20/12/21 [dayfirst=1, yearfirst=0] -> 2021-12-20 00:00:00

is_lt_253 = dateutil.__version__ < LooseVersion('2.5.3')
is_lt_253 = LooseVersion(dateutil.__version__) < LooseVersion('2.5.3')

# str : dayfirst, yearfirst, expected
cases = {'10-11-12': [(False, False,
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/indexes/timedeltas/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ def test_ops_ndarray(self):
other = pd.to_timedelta(['1 day']).values
expected = pd.to_timedelta(['2 days']).values
tm.assert_numpy_array_equal(td + other, expected)
if LooseVersion(np.__version__) >= '1.8':
if LooseVersion(np.__version__) >= LooseVersion('1.8'):
tm.assert_numpy_array_equal(other + td, expected)
pytest.raises(TypeError, lambda: td + np.array([1]))
pytest.raises(TypeError, lambda: np.array([1]) + td)

expected = pd.to_timedelta(['0 days']).values
tm.assert_numpy_array_equal(td - other, expected)
if LooseVersion(np.__version__) >= '1.8':
if LooseVersion(np.__version__) >= LooseVersion('1.8'):
tm.assert_numpy_array_equal(-other + td, expected)
pytest.raises(TypeError, lambda: td - np.array([1]))
pytest.raises(TypeError, lambda: np.array([1]) - td)
Expand All @@ -436,20 +436,20 @@ def test_ops_ndarray(self):

tm.assert_numpy_array_equal(td / other,
np.array([1], dtype=np.float64))
if LooseVersion(np.__version__) >= '1.8':
if LooseVersion(np.__version__) >= LooseVersion('1.8'):
tm.assert_numpy_array_equal(other / td,
np.array([1], dtype=np.float64))

# timedelta, datetime
other = pd.to_datetime(['2000-01-01']).values
expected = pd.to_datetime(['2000-01-02']).values
tm.assert_numpy_array_equal(td + other, expected)
if LooseVersion(np.__version__) >= '1.8':
if LooseVersion(np.__version__) >= LooseVersion('1.8'):
tm.assert_numpy_array_equal(other + td, expected)

expected = pd.to_datetime(['1999-12-31']).values
tm.assert_numpy_array_equal(-td + other, expected)
if LooseVersion(np.__version__) >= '1.8':
if LooseVersion(np.__version__) >= LooseVersion('1.8'):
tm.assert_numpy_array_equal(other - td, expected)

def test_ops_series(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/internals/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pandas.compat import zip, u

# in 3.6.1 a c-api slicing function changed, see src/compat_helper.h
PY361 = sys.version >= LooseVersion('3.6.1')
PY361 = LooseVersion(sys.version) >= LooseVersion('3.6.1')


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
div_style = ''
try:
import IPython
if IPython.__version__ < LooseVersion('3.0.0'):
if LooseVersion(IPython.__version__) < LooseVersion('3.0.0'):
div_style = ' style="max-width:1500px;overflow:auto;"'
except (ImportError, AttributeError):
pass
Expand Down
Loading