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

CLN: Dead version checking code post minimum version bump #27063

Merged
merged 9 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 9 additions & 4 deletions pandas/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import re

from pandas.compat import raise_with_traceback
from pandas.compat._optional import import_optional_dependency
from pandas.compat._optional import (
VERSIONS, import_optional_dependency, version_message)
from pandas.errors import AbstractMethodError, EmptyDataError

from pandas.core.dtypes.common import is_list_like
Expand Down Expand Up @@ -831,9 +832,13 @@ def _parser_dispatch(flavor):
raise ImportError(
"BeautifulSoup4 (bs4) not found, please install it")
import bs4
if LooseVersion(bs4.__version__) <= LooseVersion('4.2.0'):
raise ValueError("A minimum version of BeautifulSoup 4.2.1 "
"is required")
minimum_bs4_version = VERSIONS['bs4']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does bs4 = import_optional_dependency('bs4') work here? I don't recall why I didn't use it.

Copy link
Member Author

@mroeschke mroeschke Jun 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this actually done above:

def _importers():
    # import things we need
    # but make this done on a first use basis

    global _IMPORTS
    if _IMPORTS:
        return

    global _HAS_BS4, _HAS_LXML, _HAS_HTML5LIB
    bs4 = import_optional_dependency("bs4", raise_on_missing=False,
                                     on_version="ignore")
    _HAS_BS4 = bs4 is not None

But I think you're right; bs4 = import_optional_dependency('bs4') can be called here again with the raising behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so this wasn't changed because import_optional_dependency will raise a ImportError while this path raises a ValueError (there's a test for this).

I think it's worth changing to an ImportError. Thoughts @TomAugspurger?

if LooseVersion(bs4.__version__) < LooseVersion(minimum_bs4_version):
raise ImportError(version_message.format(
minimum_bs4_version,
'bs4',
bs4.__version__
))

else:
if not _HAS_LXML:
Expand Down
5 changes: 0 additions & 5 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import copy
from datetime import date, datetime
from distutils.version import LooseVersion
import itertools
import os
import re
Expand Down Expand Up @@ -227,10 +226,6 @@ def _tables():
import tables
_table_mod = tables

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

# set the file open policy
# return the file open policy; this changes as of pytables 3.1
# depending on the HDF5 version
Expand Down
13 changes: 4 additions & 9 deletions pandas/tests/indexes/datetimes/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Tests for DatetimeIndex timezone-related methods
"""
from datetime import date, datetime, time, timedelta, tzinfo
from distutils.version import LooseVersion

import dateutil
from dateutil.tz import gettz, tzlocal
Expand Down Expand Up @@ -554,14 +553,10 @@ def test_dti_construction_ambiguous_endpoint(self, tz):
assert times[0] == Timestamp('2013-10-26 23:00', tz=tz, freq="H")

if str(tz).startswith('dateutil'):
if LooseVersion(dateutil.__version__) < LooseVersion('2.6.0'):
# see GH#14621
assert times[-1] == Timestamp('2013-10-27 01:00:00+0000',
tz=tz, freq="H")
elif LooseVersion(dateutil.__version__) > LooseVersion('2.6.0'):
# fixed ambiguous behavior
assert times[-1] == Timestamp('2013-10-27 01:00:00+0100',
tz=tz, freq="H")
# fixed ambiguous behavior
# see GH#14621
assert times[-1] == Timestamp('2013-10-27 01:00:00+0100',
tz=tz, freq="H")
else:
assert times[-1] == Timestamp('2013-10-27 01:00:00+0000',
tz=tz, freq="H")
Expand Down
9 changes: 0 additions & 9 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import calendar
from datetime import datetime, time
from distutils.version import LooseVersion
import locale

import dateutil
from dateutil.parser import parse
from dateutil.tz.tz import tzoffset
import numpy as np
Expand Down Expand Up @@ -1739,8 +1737,6 @@ 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 = LooseVersion(dateutil.__version__) < LooseVersion('2.5.3')

# str : dayfirst, yearfirst, expected
cases = {'10-11-12': [(False, False,
datetime(2012, 10, 11)),
Expand All @@ -1762,11 +1758,6 @@ def test_parsers_dayfirst_yearfirst(self, cache):
for date_str, values in cases.items():
for dayfirst, yearfirst, expected in values:

# odd comparisons across version
# let's just skip
if dayfirst and yearfirst and is_lt_253:
continue

# compare with dateutil result
dateutil_result = parse(date_str, dayfirst=dayfirst,
yearfirst=yearfirst)
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/io/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ def s3_resource(tips_file, jsonl_file):
"""
pytest.importorskip('s3fs')
boto3 = pytest.importorskip('boto3')
botocore = pytest.importorskip('botocore')

if LooseVersion(botocore.__version__) < LooseVersion("1.11.0"):
# botocore leaks an uncatchable ResourceWarning before 1.11.0;
# see GH 23731 and https://github.com/boto/botocore/issues/1464
pytest.skip("botocore is leaking resources before 1.11.0")

with tm.ensure_safe_environment_variables():
# temporary workaround as moto fails for botocore >= 1.11 otherwise,
Expand Down
11 changes: 2 additions & 9 deletions pandas/tests/io/excel/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,8 @@ def custom_converter(css):
assert cell1.font.color.rgb != cell2.font.color.rgb
assert cell2.font.color.rgb == alpha + '0000FF'
elif ref == 'D4':
# This fails with engine=xlsxwriter due to
# https://bitbucket.org/openpyxl/openpyxl/issues/800
if engine == 'xlsxwriter' \
and (LooseVersion(openpyxl.__version__) <
LooseVersion('2.4.6')):
pass
else:
assert cell1.font.underline != cell2.font.underline
assert cell2.font.underline == 'single'
assert cell1.font.underline != cell2.font.underline
assert cell2.font.underline == 'single'
elif ref == 'B5':
assert not cell1.border.left.style
assert (cell2.border.top.style ==
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/io/pytables/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
'release beyong 3.4.4 to support numpy 1.16x'))


_default_compressor = ('blosc' if LooseVersion(tables.__version__) >=
LooseVersion('2.2') else 'zlib')
_default_compressor = 'blosc'


ignore_natural_naming_warning = pytest.mark.filterwarnings(
Expand Down
8 changes: 2 additions & 6 deletions pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,8 @@ class TestParquetFastParquet(Base):
def test_basic(self, fp, df_full):
df = df_full

# additional supported types for fastparquet
if LooseVersion(fastparquet.__version__) >= LooseVersion('0.1.4'):
df['datetime_tz'] = pd.date_range('20130101', periods=3,
tz='US/Eastern')
df['datetime_tz'] = pd.date_range('20130101', periods=3,
tz='US/Eastern')
df['timedelta'] = pd.timedelta_range('1 day', periods=3)
check_round_trip(df, fp)

Expand Down Expand Up @@ -485,8 +483,6 @@ def test_unsupported(self, fp):
self.check_error_on_write(df, fp, ValueError)

def test_categorical(self, fp):
if LooseVersion(fastparquet.__version__) < LooseVersion("0.1.3"):
pytest.skip("CategoricalDtype not supported for older fp")
df = pd.DataFrame({'a': pd.Categorical(list('abc'))})
check_round_trip(df, fp)

Expand Down
11 changes: 2 additions & 9 deletions pandas/tests/scalar/timestamp/test_rendering.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from distutils.version import LooseVersion
import pprint

import dateutil
import pytest
import pytz # noqa # a test below uses pytz but only inside a `eval` call

Expand All @@ -10,13 +8,8 @@

class TestTimestampRendering:

# dateutil zone change (only matters for repr)
if LooseVersion(dateutil.__version__) >= LooseVersion('2.6.0'):
timezones = ['UTC', 'Asia/Tokyo', 'US/Eastern',
'dateutil/US/Pacific']
else:
timezones = ['UTC', 'Asia/Tokyo', 'US/Eastern',
'dateutil/America/Los_Angeles']
timezones = ['UTC', 'Asia/Tokyo', 'US/Eastern',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prob should use our fixture for these (future PR)

'dateutil/US/Pacific']

@pytest.mark.parametrize('tz', timezones)
@pytest.mark.parametrize('freq', ['D', 'M', 'S', 'N'])
Expand Down
28 changes: 9 additions & 19 deletions pandas/tests/scalar/timestamp/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Tests for Timestamp timezone-related methods
"""
from datetime import date, datetime, timedelta
from distutils.version import LooseVersion

import dateutil
from dateutil.tz import gettz, tzoffset
Expand Down Expand Up @@ -145,31 +144,22 @@ def test_tz_localize_ambiguous_compat(self):
assert result_pytz.value == result_dateutil.value
assert result_pytz.value == 1382835600000000000

if LooseVersion(dateutil.__version__) < LooseVersion('2.6.0'):
# dateutil 2.6 buggy w.r.t. ambiguous=0
# see gh-14621
# see https://github.com/dateutil/dateutil/issues/321
assert (result_pytz.to_pydatetime().tzname() ==
result_dateutil.to_pydatetime().tzname())
assert str(result_pytz) == str(result_dateutil)
elif LooseVersion(dateutil.__version__) > LooseVersion('2.6.0'):
# fixed ambiguous behavior
assert result_pytz.to_pydatetime().tzname() == 'GMT'
assert result_dateutil.to_pydatetime().tzname() == 'BST'
assert str(result_pytz) != str(result_dateutil)
# fixed ambiguous behavior
# see gh-14621
assert result_pytz.to_pydatetime().tzname() == 'GMT'
assert result_dateutil.to_pydatetime().tzname() == 'BST'
assert str(result_pytz) != str(result_dateutil)

# 1 hour difference
result_pytz = naive.tz_localize(pytz_zone, ambiguous=1)
result_dateutil = naive.tz_localize(dateutil_zone, ambiguous=1)
assert result_pytz.value == result_dateutil.value
assert result_pytz.value == 1382832000000000000

# dateutil < 2.6 is buggy w.r.t. ambiguous timezones
if LooseVersion(dateutil.__version__) > LooseVersion('2.5.3'):
# see gh-14621
assert str(result_pytz) == str(result_dateutil)
assert (result_pytz.to_pydatetime().tzname() ==
result_dateutil.to_pydatetime().tzname())
# see gh-14621
assert str(result_pytz) == str(result_dateutil)
assert (result_pytz.to_pydatetime().tzname() ==
result_dateutil.to_pydatetime().tzname())

@pytest.mark.parametrize('tz', [pytz.timezone('US/Eastern'),
gettz('US/Eastern'),
Expand Down
20 changes: 0 additions & 20 deletions pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import date, datetime, timedelta
from distutils.version import LooseVersion

import numpy as np
import pytest
Expand Down Expand Up @@ -2998,25 +2997,6 @@ def _make_timestamp(self, string, hrs_offset, tz):
offset_string = '-{hrs:02d}00'.format(hrs=-1 * hrs_offset)
return Timestamp(string + offset_string).tz_convert(tz)

def test_fallback_plural(self):
# test moving from daylight savings to standard time
import dateutil
for tz, utc_offsets in self.timezone_utc_offsets.items():
hrs_pre = utc_offsets['utc_offset_daylight']
hrs_post = utc_offsets['utc_offset_standard']

if LooseVersion(dateutil.__version__) < LooseVersion('2.6.0'):
# buggy ambiguous behavior in 2.6.0
# GH 14621
# https://github.com/dateutil/dateutil/issues/321
self._test_all_offsets(
n=3, tstart=self._make_timestamp(self.ts_pre_fallback,
hrs_pre, tz),
expected_utc_offset=hrs_post)
elif LooseVersion(dateutil.__version__) > LooseVersion('2.6.0'):
# fixed, but skip the test
continue

def test_springforward_plural(self):
# test moving from standard to daylight savings
for tz, utc_offsets in self.timezone_utc_offsets.items():
Expand Down