Skip to content

Commit

Permalink
MAINT: remove never-needed callable and never-used compat functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and bashtage committed May 1, 2019
1 parent 319ddc6 commit 662f825
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 53 deletions.
49 changes: 3 additions & 46 deletions statsmodels/compat/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pickle = cPickle
import urllib.request
import urllib.parse
from urllib.request import HTTPError, urlretrieve, URLError
from urllib.request import HTTPError, URLError
import io
bytes = bytes
str = str
Expand All @@ -45,14 +45,6 @@ def asstr2(s): #added JP, not in numpy version
else:
return str(s)

def isfileobj(f):
return isinstance(f, io.FileIO)

def open_latin1(filename, mode='r'):
return open(filename, mode=mode, encoding='iso-8859-1')

strchar = 'U'

# have to explicitly put builtins into the namespace
range = range
map = map
Expand Down Expand Up @@ -81,7 +73,6 @@ def lfilter(*args, **kwargs):
urlretrieve = urllib.request.urlretrieve
urlencode = urllib.parse.urlencode
string_types = str
input = input

ArgSpec= namedtuple('ArgSpec', ['args', 'varargs', 'keywords', 'defaults'])
def getargspec(func):
Expand Down Expand Up @@ -129,19 +120,12 @@ def getargspec(func):
asbytes = str
asstr = str
asstr2 = str
strchar = 'S'

def isfileobj(f):
return isinstance(f, file)

def asunicode(s, encoding='ascii'):
if isinstance(s, unicode):
return s
return s.decode(encoding)

def open_latin1(filename, mode='r'):
return open(filename, mode=mode)

# import iterator versions of these functions
range = xrange
zip = itertools.izip
Expand All @@ -165,41 +149,14 @@ def open_latin1(filename, mode='r'):
URLError = urllib2.URLError
string_types = basestring

input = raw_input


def getexception():
return sys.exc_info()[1]


def asbytes_nested(x):
if hasattr(x, '__iter__') and not isinstance(x, (bytes, str)):
return [asbytes_nested(y) for y in x]
else:
return asbytes(x)


def asunicode_nested(x):
if hasattr(x, '__iter__') and not isinstance(x, (bytes, str)):
return [asunicode_nested(y) for y in x]
else:
return asunicode(x)


try:
advance_iterator = next
next = next
except NameError:
def advance_iterator(it):
def next(it):
return it.next()
next = advance_iterator


try:
callable = callable
except NameError:
def callable(obj):
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)

def iteritems(obj, **kwargs):
"""replacement for six's iteritems for Python2/3 compat
uses 'iteritems' if available and otherwise uses 'items'.
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/discrete/discrete_margins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Splitting out maringal effects to see if they can be generalized

from statsmodels.compat.python import lzip, callable, range
from statsmodels.compat.python import lzip, range
import numpy as np
from scipy.stats import norm
from statsmodels.tools.decorators import cache_readonly, resettable_cache
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/robust/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
R Venables, B Ripley. 'Modern Applied Statistics in S'
Springer, New York, 2002.
"""
from statsmodels.compat.python import callable, range
from statsmodels.compat.python import range
import numpy as np
from scipy.stats import norm as Gaussian
from . import norms
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/sandbox/distributions/gof_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'''
from __future__ import print_function
from statsmodels.compat.python import range, lmap, string_types, callable
from statsmodels.compat.python import range, lmap, string_types
import numpy as np

from scipy.stats import distributions
Expand Down
4 changes: 2 additions & 2 deletions statsmodels/sandbox/formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"""
from collections import OrderedDict
from statsmodels.compat.python import (iterkeys, lrange, callable, string_types,
itervalues, range)
from statsmodels.compat.python import (iterkeys, lrange, string_types,
itervalues, range)
import copy
import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion statsmodels/sandbox/nonparametric/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# pylint: disable-msg=W0142
# pylint: disable-msg=E1101
# pylint: disable-msg=E0611
from statsmodels.compat.python import lzip, lfilter, callable, zip
from statsmodels.compat.python import lzip, lfilter, zip
import numpy as np
import scipy.integrate
from statsmodels.compat.scipy import factorial
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/tsa/base/datetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Tools for working with dates
"""
from statsmodels.compat.python import (lrange, lzip, lmap,
asstr, reduce, zip, map)
asstr, zip, map)
import re
import datetime

Expand Down

0 comments on commit 662f825

Please sign in to comment.