Skip to content

Commit

Permalink
corrections concerning Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeyhardi committed Jan 17, 2019
1 parent 62968e5 commit d2ba4a3
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 52 deletions.
14 changes: 7 additions & 7 deletions src/py/statiskit/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def set_dispersion(self, dispersion):
def wrapper_set_name(f):
@wraps(f)
def set_name(self, name):
if not isinstance(name, basestring):
if not isinstance(name, str):
raise TypeError('expected basestring, but got {!r}'.format(type(name)))
is_name = True
try:
Expand Down Expand Up @@ -128,7 +128,7 @@ def __len__(self):
@wraps(f1)
def __getitem__(self, index):
if isinstance(index, slice):
return [self[index] for index in xrange(*index.indices(len(self)))]
return [self[index] for index in range(*index.indices(len(self)))]
else:
if index < 0:
index += len(self)
Expand Down Expand Up @@ -173,7 +173,7 @@ def __str__(self):
rows = [("", str(self.name))] + [(str(index), str(event)) if event is not None else (repr(index), '?') for index, event in enumerate(events) if index < controls.head] + [('...', '...')] + [(repr(index), repr(event)) if event is not None else (repr(index), '?') for index, event in enumerate(events) if index > max(len(events) - controls.tail, controls.head)]
else:
rows = [("", str(self.name))] + [(str(index), str(event)) if event is not None else (repr(index), '?') for index, event in enumerate(events)]
columns = zip(*rows)
columns = list(zip(*rows))
maxima = [max(max(*[len(row) for row in column]), 3) + 2 for column in columns]
string = []
for index, row in enumerate(rows):
Expand Down Expand Up @@ -203,7 +203,7 @@ def _repr_html_(self):
del _repr_html_

def pdf_plot(self, axes=None, **kwargs):
from estimation import frequency_estimation, histogram_estimation
from .estimation import frequency_estimation, histogram_estimation
sample_space = self.sample_space
norm = kwargs.pop('norm', False)
if isinstance(norm, bool):
Expand Down Expand Up @@ -236,7 +236,7 @@ def pdf_plot(self, axes=None, **kwargs):
del pdf_plot

def cdf_plot(self, axes=None, **kwargs):
from estimation import frequency_estimation
from .estimation import frequency_estimation
sample_space = self.sample_space
norm = kwargs.pop('norm', False)
if isinstance(norm, bool):
Expand All @@ -260,7 +260,7 @@ def cdf_plot(self, axes=None, **kwargs):
del cdf_plot

def box_plot(self, axes=None, **kwargs):
from estimation import frequency_estimation
from .estimation import frequency_estimation
sample_space = self.sample_space
norm = kwargs.pop('norm', False)
if isinstance(norm, bool):
Expand Down Expand Up @@ -486,7 +486,7 @@ def __repr__(self):
rows = [[""] + [repr(component.name) for component in self.components]] + [[repr(index)] + [repr(uevent) if uevent is not None else '?' for uevent in mevent] for index, mevent in enumerate(events) if index < controls.head] + [['...'] + ['...'] * len(self.components)] + [[repr(index)] + [repr(uevent) if uevent is not None else '?' for uevent in mevent] for index, mevent in enumerate(events) if index > max(len(events) - controls.tail, controls.head)]
else:
rows = [[""] + [repr(component.name) for component in self.components]] + [[repr(index)] + [repr(uevent) if uevent is not None else '?' for uevent in mevent] for index, mevent in enumerate(events)]
columns = zip(*rows)
columns = list(zip(*rows))
maxima = [max(max(*[len(row) for row in column]), 3) + 2 for column in columns]
string = []
for index, row in enumerate(rows):
Expand Down
24 changes: 12 additions & 12 deletions src/py/statiskit/core/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _repr_latex_(self):
def wrapper_probability(f):
@wraps(f)
def probability(self, event, **kwargs):
if isinstance(event, basestring):
if isinstance(event, str):
event = CategoricalElementaryEvent(event)
elif isinstance(event, int):
event = DiscreteElementaryEvent(event)
Expand Down Expand Up @@ -164,7 +164,7 @@ def pdf_plot(self, axes=None, fmt='|', **kwargs):
if axes is None:
axes = pyplot.subplot(1,1,1)
labels = getattr(self, 'ordered_values', getattr(self, 'values'))
x, labels = zip(*[(index, label) for index, label in enumerate(labels)])
x, labels = list(zip(*[(index, label) for index, label in enumerate(labels)]))
y = [self.probability(label, log=False) for label in labels]
if 'norm' in kwargs:
norm = kwargs.pop('norm')
Expand Down Expand Up @@ -198,7 +198,7 @@ def wrapper(f):
@wraps(f)
def __init__(self, *args, **kwargs):
f(self, args)
for attr in kwargs.keys():
for attr in list(kwargs.keys()):
if hasattr(self, attr):
setattr(self, attr, kwargs.pop(attr))
else:
Expand Down Expand Up @@ -229,15 +229,15 @@ def cdf_plot(self, axes=None, fmt='|', **kwargs):
if axes is None:
axes = pyplot.subplot(1,1,1)
labels = self.ordered_values
x, labels = zip(*[(index, label) for index, label in enumerate(labels)])
x, labels = list(zip(*[(index, label) for index, label in enumerate(labels)]))
y = self.pi
if 'norm' in kwargs:
norm = kwargs.pop('norm')
y = [norm * p for p in y]
else:
y = [p for p in y]
y = [y[i] for i in self.rank]
y = [sum(y[:i]) for i in xrange(1, len(y)+1)]
y = [sum(y[:i]) for i in range(1, len(y)+1)]
if '|' in fmt:
fmt = fmt.replace('|', '')
width = kwargs.pop('width', .8)
Expand Down Expand Up @@ -281,7 +281,7 @@ def box_plot(self, axes=None, edgecolor="k", width=.5, vert=True, whiskers=(.09,
axes.plot([pos-width/2., pos+width/2.], [qe, qe], color=edgecolor)
axes.plot([pos, pos], [qb, q1], color=edgecolor)
axes.plot([pos, pos], [q3, qe], color=edgecolor)
axes.set_yticks(range(len(values)))
axes.set_yticks(list(range(len(values))))
axes.set_yticklabels(values)
else:
axes.bar(q1, width, q3-q1, pos-width/2., facecolor=facecolor, edgecolor=edgecolor)
Expand All @@ -290,7 +290,7 @@ def box_plot(self, axes=None, edgecolor="k", width=.5, vert=True, whiskers=(.09,
axes.plot([qe, qe], [pos-width/2., pos+width/2.], color=edgecolor)
axes.plot([qb, q1], [pos, pos], color=edgecolor)
axes.plot([q3, qe], [pos, pos], color=edgecolor)
axes.set_xticks(range(len(values)))
axes.set_xticks(list(range(len(values))))
axes.set_xticklabels(values)
return axes

Expand Down Expand Up @@ -325,7 +325,7 @@ def pdf_plot(self, axes=None, fmt='|', **kwargs):
kwargs['qmin'] = int(qmin)
if 'qmax' not in kwargs and 'pmax' not in kwargs:
kwargs['qmax'] = int(qmax)
x = kwargs.pop('quantiles', range(kwargs.pop('qmin', self.quantile(kwargs.pop('pmin', 0.025))), kwargs.pop('qmax', self.quantile(kwargs.pop('pmax', 0.975)))+1))
x = kwargs.pop('quantiles', list(range(kwargs.pop('qmin', self.quantile(kwargs.pop('pmin', 0.025))), kwargs.pop('qmax', self.quantile(kwargs.pop('pmax', 0.975)))+1)))
y = [self.pdf(q) for q in x]
if 'norm' in kwargs:
norm = kwargs.pop('norm')
Expand All @@ -352,7 +352,7 @@ def cdf_plot(self, axes=None, fmt='o-', **kwargs):
kwargs['qmin'] = int(qmin)
if 'qmax' not in kwargs and 'pmax' not in kwargs:
kwargs['qmax'] = int(qmax)
x = kwargs.pop('quantiles', range(kwargs.pop('qmin', self.quantile(kwargs.pop('pmin', 0.025))), kwargs.pop('qmax', self.quantile(kwargs.pop('pmax', 0.975)))+1))
x = kwargs.pop('quantiles', list(range(kwargs.pop('qmin', self.quantile(kwargs.pop('pmin', 0.025))), kwargs.pop('qmax', self.quantile(kwargs.pop('pmax', 0.975)))+1)))
y = [self.cdf(q) for q in x]
if 'norm' in kwargs:
norm = kwargs.pop('norm')
Expand Down Expand Up @@ -887,7 +887,7 @@ def probability(self, *events, **kwargs):
if not isinstance(event, MultivariateEvent):
event = VectorEvent(len(events))
for index, component in enumerate(events):
if isinstance(component, basestring):
if isinstance(component, str):
event[index] = CategoricalElementaryEvent(component)
elif isinstance(component, int):
event[index] = DiscreteElementaryEvent(component)
Expand All @@ -906,7 +906,7 @@ def probability(self, *events, **kwargs):
MultivariateDistribution.probability = wrapper_probability(MultivariateDistribution.probability)

def simulation(self, size):
return from_list(*map(list, zip(*[self.simulate() for index in range(size)])))
return from_list(*list(map(list, list(zip(*[self.simulate() for index in range(size)])))))

MultivariateDistribution.simulation = simulation
del simulation
Expand Down Expand Up @@ -1021,7 +1021,7 @@ def pdf_plot(self, axes=None, *args, **kwargs):
else:
skwargs = [{}] * self.nb_states
for index, (pi, observation) in enumerate(zip(self.pi, self.observations)):
for key, value in kwargs.iteritems():
for key, value in kwargs.items():
if not key in skwargs[index]:
skwargs[index][key] = value
axes = observation.pdf_plot(axes=axes, norm=pi*norm, *args, **skwargs[index])
Expand Down
14 changes: 7 additions & 7 deletions src/py/statiskit/core/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def wrapper__getitem__(f):
@wraps(f)
def __getitem__(self, index):
if isinstance(index, slice):
return [self[index] for index in xrange(*index.indices(len(self)))]
return [self[index] for index in range(*index.indices(len(self)))]
else:
if index < 0:
index += len(self)
Expand Down Expand Up @@ -238,7 +238,7 @@ def wrapper__getitem__(f):
@wraps(f)
def __getitem__(self, index):
if isinstance(index, slice):
return [self[index] for index in xrange(*index.indices(len(self)))]
return [self[index] for index in range(*index.indices(len(self)))]
else:
if index < 0:
index += len(self)
Expand All @@ -254,7 +254,7 @@ def wrapper__setitem__(f):
@wraps(f)
def __setitem__(self, index, estimator):
if isinstance(index, slice):
return [self[index] for index in xrange(*index.indices(len(self)))]
return [self[index] for index in range(*index.indices(len(self)))]
else:
if index < 0:
index += len(self)
Expand Down Expand Up @@ -301,7 +301,7 @@ def __len__(self):
@wraps(f1)
def __getitem__(self, index):
if isinstance(index, slice):
return [self[index] for index in xrange(*index.indices(len(self)))]
return [self[index] for index in range(*index.indices(len(self)))]
else:
if index < 0:
index += len(self)
Expand Down Expand Up @@ -333,12 +333,12 @@ def _estimation(algo, data, mapping, **kwargs):
try:
algo = mapping[algo]()
except KeyError:
raise ValueError('\'algo\' parameter, possible values are ' + ', '.join('"' + algo + '"' for algo in mapping.iterkeys()))
raise ValueError('\'algo\' parameter, possible values are ' + ', '.join('"' + algo + '"' for algo in mapping.keys()))
except:
raise
if data:
lazy = kwargs.pop('lazy', False)
for attr in kwargs.keys():
for attr in list(kwargs.keys()):
if hasattr(algo, attr):
setattr(algo, attr, kwargs.pop(attr))
else:
Expand Down Expand Up @@ -503,7 +503,7 @@ def singular_selection(*args, **kwargs):
mapping = dict(criterion = SingularDistributionSelection.CriterionEstimator)
estimators = []
for arg in args:
estimators.append(singular_selection(arg, **dict((key, value) for (key, value) in kwargs.iteritems() if key == "sum")))
estimators.append(singular_selection(arg, **dict((key, value) for (key, value) in kwargs.items() if key == "sum")))
kwargs.pop('sum', None)
return _estimation(algo, data, mapping, estimators=estimators, **kwargs)

Expand Down
6 changes: 3 additions & 3 deletions src/py/statiskit/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
del UnivariateEvent.get_event

def type_to_event(event):
if isinstance(event, basestring):
if isinstance(event, str):
event = CategoricalElementaryEvent(event)
elif isinstance(event, int):
event = DiscreteElementaryEvent(event)
Expand Down Expand Up @@ -263,7 +263,7 @@ def wrapper(f):
@wraps(f)
def __getitem__(self, index):
if isinstance(index, slice):
return [self[_index] for _index in xrange(*index.indices(len(self)))]
return [self[_index] for _index in range(*index.indices(len(self)))]
else:
if index < 0:
index += len(self)
Expand Down Expand Up @@ -291,7 +291,7 @@ def wrapper(f):
@wraps(f)
def __setitem__(self, index, event):
if isinstance(index, slice):
for _index, _event in zip(xrange(*index.indices(len(self))), event):
for _index, _event in zip(range(*index.indices(len(self))), event):
self[_index] = _event
if index < 0:
index += len(self)
Expand Down
16 changes: 8 additions & 8 deletions src/py/statiskit/core/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def location_estimation(algo='mean', data="univariate", **kwargs):
try:
algo = mapping[algo]()
except KeyError:
raise ValueError('\'algo\' parameter, possible values are ' + ', '.join('"' + algo + '"' for algo in mapping.iterkeys()))
raise ValueError('\'algo\' parameter, possible values are ' + ', '.join('"' + algo + '"' for algo in mapping.keys()))
except:
raise
for attr in kwargs.keys():
for attr in list(kwargs.keys()):
if hasattr(algo, attr):
setattr(algo, attr, kwargs.pop(attr))
if data:
Expand All @@ -103,10 +103,10 @@ def location_estimation(algo='mean', data="univariate", **kwargs):
try:
algo = mapping[algo]()
except KeyError:
raise ValueError('\'algo\' parameter, possible values are ' + ', '.join('"' + algo + '"' for algo in mapping.iterkeys()))
raise ValueError('\'algo\' parameter, possible values are ' + ', '.join('"' + algo + '"' for algo in mapping.keys()))
except:
raise
for attr in kwargs.keys():
for attr in list(kwargs.keys()):
if hasattr(algo, attr):
setattr(algo, attr, kwargs.pop(attr))
if isinstance(data, UnivariateData):
Expand Down Expand Up @@ -145,10 +145,10 @@ def dispersion_estimation(algo='variance', data="univariate", **kwargs):
try:
algo = mapping[algo]()
except KeyError:
raise ValueError('\'algo\' parameter, possible values are ' + ', '.join('"' + algo + '"' for algo in mapping.iterkeys()))
raise ValueError('\'algo\' parameter, possible values are ' + ', '.join('"' + algo + '"' for algo in mapping.keys()))
except:
raise
for attr in kwargs.keys():
for attr in list(kwargs.keys()):
if hasattr(algo, attr):
setattr(algo, attr, kwargs.pop(attr))
if data:
Expand All @@ -160,10 +160,10 @@ def dispersion_estimation(algo='variance', data="univariate", **kwargs):
try:
algo = mapping[algo]()
except KeyError:
raise ValueError('\'algo\' parameter, possible values are ' + ', '.join('"' + algo + '"' for algo in mapping.iterkeys()))
raise ValueError('\'algo\' parameter, possible values are ' + ', '.join('"' + algo + '"' for algo in mapping.keys()))
except:
raise
for attr in kwargs.keys():
for attr in list(kwargs.keys()):
if hasattr(algo, attr):
setattr(algo, attr, kwargs.pop(attr))
if isinstance(data, UnivariateData):
Expand Down
4 changes: 2 additions & 2 deletions src/py/statiskit/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def read_csv(filepath, sep=None, header=False, **kwargs):
"""
"""
if sep and not isinstance(sep, basestring):
if sep and not isinstance(sep, str):
raise TypeError('\'sep\' parameter')
with open(filepath, 'r') as filehandler:
lines = filehandler.readlines()
Expand All @@ -39,7 +39,7 @@ def write_csv(data, filepath, sep=' ', header=False, censored=True):
"""
if not isinstance(data, MultivariateDataFrame):
raise TypeError('\'data\' parameter')
if not isinstance(sep, basestring):
if not isinstance(sep, str):
raise TypeError('\'sep\' parameter')
with open(filepath, 'w') as filehandler:
if header:
Expand Down
8 changes: 4 additions & 4 deletions src/py/statiskit/core/sample_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __call__(self, event):
"""
if event is None or isinstance(event, CategoricalEvent):
return event
elif isinstance(event, basestring):
elif isinstance(event, str):
event = event.strip()
if event in ['', '?']:
return None
Expand Down Expand Up @@ -105,7 +105,7 @@ def getter(self):

@wraps(g)
def setter(self, encoding):
if isinstance(encoding, basestring):
if isinstance(encoding, str):
encoding = encoding_type.names[encoding.upper()]
g(self, encoding)

Expand Down Expand Up @@ -145,7 +145,7 @@ def __call__(self, event):
return event
elif isinstance(event, int):
return DiscreteElementaryEvent(event)
elif isinstance(event, basestring):
elif isinstance(event, str):
event = event.replace('\n', '').strip(' ')
if event in ['', '?']:
return None
Expand Down Expand Up @@ -244,7 +244,7 @@ def __call__(self, event):
return ContinuousElementaryEvent(event)
else:
return None
elif isinstance(event, basestring):
elif isinstance(event, str):
event = event.replace('\n', '').strip(' ')
if event in ['', '?']:
return None
Expand Down
2 changes: 1 addition & 1 deletion src/py/statiskit/core/singular.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def probability(self, *events, **kwargs):
if not isinstance(event, MultivariateEvent):
event = VectorEvent(len(events))
for index, component in enumerate(events):
if isinstance(component, basestring):
if isinstance(component, str):
event[index] = CategoricalElementaryEvent(component)
elif isinstance(component, int):
event[index] = DiscreteElementaryEvent(component)
Expand Down
Loading

0 comments on commit d2ba4a3

Please sign in to comment.