Skip to content

Commit 7252192

Browse files
committed
MAINT: Remove more compat shims
Remove the remainder of the easy to replace shims
1 parent 5e78c86 commit 7252192

File tree

16 files changed

+37
-103
lines changed

16 files changed

+37
-103
lines changed

statsmodels/compat/__init__.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22

33
from .python import (
44
PY37,
5-
asunicode, asbytes, asstr, asstr2,
5+
asunicode, asbytes, asstr,
66
lrange, lzip, lmap, lfilter,
77
iteritems, iterkeys, itervalues,
8-
urlopen, urljoin, urlencode, HTTPError, URLError,
9-
getargspec, next, get_class
108
)
119

1210
__all__ = ['PY37',
13-
'asunicode', 'asbytes', 'asstr', 'asstr2',
11+
'asunicode', 'asbytes', 'asstr',
1412
'lrange', 'lzip', 'lmap', 'lfilter',
15-
'iteritems',
16-
'iterkeys', 'itervalues', 'urlopen', 'urljoin', 'urlencode',
17-
'HTTPError', 'URLError',
18-
'getargspec', 'next', 'get_class', 'test']
13+
'iteritems', 'iterkeys', 'itervalues',
14+
'test']
1915

2016
test = PytestTester()

statsmodels/compat/python.py

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
"""
22
Compatibility tools for differences between Python 2 and 3
33
"""
4-
__all__ = ['HTTPError', 'URLError']
5-
64
import sys
7-
import urllib
8-
import inspect
9-
from collections import namedtuple
10-
import urllib.request
11-
import urllib.parse
12-
from urllib.error import HTTPError, URLError
135

146
PY37 = (sys.version_info[:2] == (3, 7))
157

@@ -28,15 +20,6 @@ def asstr(s):
2820
return s.decode('latin1')
2921

3022

31-
def asstr2(s): # added JP, not in numpy version
32-
if isinstance(s, str):
33-
return s
34-
elif isinstance(s, bytes):
35-
return s.decode('latin1')
36-
else:
37-
return str(s)
38-
39-
4023
# list-producing versions of the major Python iterating functions
4124
def lrange(*args, **kwargs):
4225
return list(range(*args, **kwargs))
@@ -54,48 +37,6 @@ def lfilter(*args, **kwargs):
5437
return list(filter(*args, **kwargs))
5538

5639

57-
urlopen = urllib.request.urlopen
58-
urljoin = urllib.parse.urljoin
59-
urlretrieve = urllib.request.urlretrieve
60-
urlencode = urllib.parse.urlencode
61-
62-
ArgSpec = namedtuple('ArgSpec',
63-
['args', 'varargs', 'keywords', 'defaults'])
64-
65-
66-
def getargspec(func):
67-
"""
68-
Simple workaroung for getargspec deprecation that returns
69-
an ArgSpec-like object
70-
"""
71-
sig = inspect.signature(func)
72-
parameters = sig.parameters
73-
args, defaults = [], []
74-
varargs, keywords = None, None
75-
76-
for key in parameters:
77-
parameter = parameters[key]
78-
79-
if parameter.kind == inspect.Parameter.VAR_POSITIONAL:
80-
varargs = key
81-
elif parameter.kind == inspect.Parameter.VAR_KEYWORD:
82-
keywords = key
83-
else:
84-
args.append(key)
85-
if parameter.default is not parameter.empty:
86-
defaults.append(parameter.default)
87-
defaults = None if len(defaults) == 0 else defaults
88-
89-
return ArgSpec(args, varargs, keywords, defaults)
90-
91-
92-
try:
93-
next = next
94-
except NameError:
95-
def next(it):
96-
return it.next()
97-
98-
9940
def iteritems(obj, **kwargs):
10041
"""replacement for six's iteritems for Python2/3 compat
10142
uses 'iteritems' if available and otherwise uses 'items'.
@@ -122,14 +63,6 @@ def itervalues(obj, **kwargs):
12263
return func(**kwargs)
12364

12465

125-
def get_class(func):
126-
try:
127-
return func.im_class
128-
except AttributeError:
129-
# Python 3
130-
return func.__self__.__class__
131-
132-
13366
def with_metaclass(meta, *bases):
13467
"""Create a base class with a metaclass."""
13568
# This requires a bit of explanation: the basic idea is to make a dummy

statsmodels/datasets/tests/test_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from statsmodels.compat.python import HTTPError, URLError
2-
31
import os
42
from ssl import SSLError
53
from socket import timeout
4+
from urllib.error import HTTPError, URLError
65

76
import numpy as np
87
from numpy.testing import assert_, assert_array_equal

statsmodels/datasets/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
from statsmodels.compat.python import (urlopen, HTTPError, URLError,
2-
lrange, urljoin)
1+
from statsmodels.compat.python import lrange
2+
33
from io import StringIO
44
import pickle
55
import shutil
66
from os import environ, makedirs
77
from os.path import expanduser, exists, dirname, abspath, join
8+
from urllib.error import HTTPError, URLError
9+
from urllib.request import urlopen
10+
from urllib.parse import urljoin
811

912
import numpy as np
1013
from pandas import read_stata, read_csv, DataFrame, Series, Index

statsmodels/distributions/empirical_distribution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def monotone_fn_inverter(fn, x, vectorized=True, **keywords):
167167
if __name__ == "__main__":
168168
#TODO: Make sure everything is correctly aligned and make a plotting
169169
# function
170-
from statsmodels.compat.python import urlopen
170+
from urllib.request import urlopen
171171
import matplotlib.pyplot as plt
172172
nerve_data = urlopen('http://www.statsci.org/data/general/nerve.txt')
173173
nerve_data = np.loadtxt(nerve_data)

statsmodels/examples/ex_sandwich2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
Created on Fri Dec 16 12:52:13 2011
55
Author: Josef Perktold
66
"""
7+
from urllib.request import urlretrieve
78

8-
from statsmodels.compat.python import urlretrieve
99
import numpy as np
1010
from numpy.testing import assert_almost_equal
1111

statsmodels/examples/ex_sandwich3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
66
Author: Josef Perktold
77
"""
8-
from statsmodels.compat.python import urlretrieve
8+
from urllib.request import urlretrieve
9+
910
import numpy as np
1011
from numpy.testing import assert_almost_equal
1112

statsmodels/iolib/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def mylabeller(cell):
8282
:change: 2010-05-06 add `label_cells` to `SimpleTable`
8383
"""
8484

85-
from statsmodels.compat.python import lmap, lrange, next, iteritems
85+
from statsmodels.compat.python import lmap, lrange, iteritems
8686

8787
from itertools import cycle, zip_longest
8888
import csv

statsmodels/nonparametric/kernel_density.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
2929
"""
3030
# TODO: make default behavior efficient=True above a certain n_obs
31-
32-
from statsmodels.compat.python import next
3331
import numpy as np
3432

3533
from . import kernels

statsmodels/nonparametric/kernel_regression.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
"""
3030

3131
# TODO: make default behavior efficient=True above a certain n_obs
32-
33-
from statsmodels.compat.python import next
3432
import copy
3533

3634
import numpy as np

0 commit comments

Comments
 (0)