Address deprecation of Python ABC. (#3909)

This commit is contained in:
Jiaming Yuan 2018-11-16 19:43:32 +13:00 committed by GitHub
parent aa48b7e903
commit 93f63324e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,8 +3,13 @@
# pylint: disable=too-many-branches, too-many-lines, W0141 # pylint: disable=too-many-branches, too-many-lines, W0141
"""Core XGBoost Library.""" """Core XGBoost Library."""
from __future__ import absolute_import from __future__ import absolute_import
import collections import collections
# pylint: disable=no-name-in-module,import-error
try:
from collections.abc import Mapping # Python 3
except ImportError:
from collections import Mapping # Python 2
# pylint: enable=no-name-in-module,import-error
import ctypes import ctypes
import os import os
import re import re
@ -13,9 +18,11 @@ import sys
import numpy as np import numpy as np
import scipy.sparse import scipy.sparse
from .compat import STRING_TYPES, PY3, DataFrame, MultiIndex, py_str, PANDAS_INSTALLED, DataTable from .compat import (STRING_TYPES, PY3, DataFrame, MultiIndex, py_str,
PANDAS_INSTALLED, DataTable)
from .libpath import find_lib_path from .libpath import find_lib_path
# c_bst_ulong corresponds to bst_ulong defined in xgboost/c_api.h # c_bst_ulong corresponds to bst_ulong defined in xgboost/c_api.h
c_bst_ulong = ctypes.c_uint64 c_bst_ulong = ctypes.c_uint64
@ -1021,7 +1028,7 @@ class Booster(object):
value: optional value: optional
value of the specified parameter, when params is str key value of the specified parameter, when params is str key
""" """
if isinstance(params, collections.Mapping): if isinstance(params, Mapping):
params = params.items() params = params.items()
elif isinstance(params, STRING_TYPES) and value is not None: elif isinstance(params, STRING_TYPES) and value is not None:
params = [(params, value)] params = [(params, value)]