Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jpn--/larch
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed Aug 30, 2017
2 parents 7c0597c + b19caf4 commit 57c2437
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 160 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sqlite/* linguist-vendored
6 changes: 3 additions & 3 deletions doc/_static/larch_rtfd.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ div.larch_art table, div.larch_art th, div.larch_art td {
font-weight:400;
}

div.larch_art th, div.larch_art td { padding:2px; }
div.larch_art th, div.larch_art td { padding:2px; text-align:left;}

div.larch_art td.parameter_category {
font-family:"Roboto", monospace;
Expand Down Expand Up @@ -225,7 +225,8 @@ h3.larch_art, h3.larch_art_xhtml {
h2.larch_art + h3.larch_art, h2.larch_art_xhtml + h3.larch_art_xhtml,
h2.larch_art + a.toc + h3.larch_art, h2.larch_art_xhtml + a.toc + h3.larch_art_xhtml {
margin-top: 5px;

}

table.dictionary {
border:0px hidden !important;
border-collapse: collapse !important;
Expand All @@ -236,4 +237,3 @@ div.blurb {
max-width: 6.5in;
}

}
10 changes: 5 additions & 5 deletions py/dt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def array_idca(self, *vars, dtype=numpy.float64, screen=None, strip_nan=True):
An array with specified dtype, of shape (n_cases,n_alts,len(vars)).
"""
from numpy import log, exp, log1p, absolute, fabs, sqrt, isnan, isfinite, logaddexp, fmin, fmax
from numpy import log, exp, log1p, absolute, fabs, sqrt, isnan, isfinite, logaddexp, fmin, fmax, nan_to_num
from ..util.pytables_addon import select_with_repeated1
from ..util.aster import inXd
screen, n_cases = self.process_proposed_screen(screen)
Expand Down Expand Up @@ -800,7 +800,7 @@ def array_idco(self, *vars, dtype=numpy.float64, screen=None, strip_nan=True, ex
data : ndarray
An array with specified dtype, of shape (n_cases,len(vars)).
"""
from numpy import log, exp, log1p, absolute, fabs, sqrt, isnan, isfinite, logaddexp, fmin, fmax
from numpy import log, exp, log1p, absolute, fabs, sqrt, isnan, isfinite, logaddexp, fmin, fmax, nan_to_num
from ..util.pytables_addon import select_with_repeated1
from ..util.aster import inXd
screen, n_cases = self.process_proposed_screen(screen)
Expand Down Expand Up @@ -869,7 +869,7 @@ def dataframe_idco(self, *vars, screen=None, strip_nan=True, explain=False):
-------
pandas.DataFrame
"""
from numpy import log, exp, log1p, absolute, fabs, sqrt, isnan, isfinite, logaddexp, fmin, fmax
from numpy import log, exp, log1p, absolute, fabs, sqrt, isnan, isfinite, logaddexp, fmin, fmax, nan_to_num
from ..util.pytables_addon import select_with_repeated1
from ..util.aster import inXd
screen, n_cases = self.process_proposed_screen(screen)
Expand Down Expand Up @@ -1406,7 +1406,7 @@ def check_ca(self, column, raise_exception=False):
return True
if self._check_co_natural(column):
return True
from numpy import log, exp, log1p, absolute, fabs, sqrt, isnan, isfinite, logaddexp, fmin, fmax
from numpy import log, exp, log1p, absolute, fabs, sqrt, isnan, isfinite, logaddexp, fmin, fmax, nan_to_num
from ..util.pytables_addon import validate_with_repeated1
from ..util.aster import inXd
try:
Expand Down Expand Up @@ -1437,7 +1437,7 @@ def multi_check_ca(self, bucket):
def check_co(self, column, raise_exception=False):
if self._check_co_natural(column):
return True
from numpy import log, exp, log1p, absolute, fabs, sqrt, isnan, isfinite, logaddexp, fmin, fmax
from numpy import log, exp, log1p, absolute, fabs, sqrt, isnan, isfinite, logaddexp, fmin, fmax, nan_to_num
from ..util.pytables_addon import validate_with_repeated1
from ..util.aster import inXd
try:
Expand Down
2 changes: 1 addition & 1 deletion py/dt/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def convert_datetime_time_to_epoch_seconds(tm):
raise
return self

def import_idca(self, filepath_or_buffer, caseid_col, altid_col, choice_col=None, force_int_as_float=True, chunksize=1e1000):
def import_idca(self, filepath_or_buffer, caseid_col, altid_col, choice_col=None, force_int_as_float=True, chunksize=1e300):
"""Import an existing CSV or similar file in idca format into this HDF5 file.
This function relies on :func:`pandas.read_csv` to read and parse the input data.
Expand Down
2 changes: 1 addition & 1 deletion py/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __call__(self, *arg):
font-weight:400;
}
div.output_wrapper th, div.output_wrapper td { padding:2px; }
div.output_wrapper th, div.output_wrapper td { padding:2px; text-align:left; }
div.output_wrapper td.parameter_category {
font-family:"Roboto", monospace;
Expand Down
24 changes: 18 additions & 6 deletions py/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,13 @@ def _set_link(self, *args):
edge = property(_core.Model2_link_get, _set_link, None, "an alias for :attr:`link`")

def alternatives(self):
return {code:name for code,name in zip(self.alternative_codes(),self.alternative_names())}
result = {code:name for code,name in zip(self.alternative_codes(),self.alternative_names())}
if len(result):
return result
try:
return self._alternatives_recall
except AttributeError:
return result

def alternative_name(self, code):
codes = numpy.asarray(self.alternative_codes())
Expand Down Expand Up @@ -522,6 +528,7 @@ def loads(self, content="@@@", *, use_base64=False, echo=False, d=None):
self = Model()
inf = numpy.inf
nan = numpy.nan
import pickle
_Str = lambda s: (base64.standard_b64decode(s)).decode()
if use_base64:
content = base64.standard_b64decode(content)
Expand All @@ -531,7 +538,6 @@ def loads(self, content="@@@", *, use_base64=False, echo=False, d=None):
content = zlib.decompress(content)
except zlib.error:
pass
import pickle
try:
content = pickle.loads(content)
except pickle.UnpicklingError:
Expand Down Expand Up @@ -579,10 +585,15 @@ def save(self, filename, overwrite=False, spool=True, report=False, report_cats=
# f.write(self.report(lineprefix="#\t", cats=report_cats))
# f.write("\n\n\n")
import time
import pickle
f.write("# saved at %s"%time.strftime("%I:%M:%S %p %Z"))
f.write(" on %s\n"%time.strftime("%d %b %Y"))
f.write(self.save_buffer())

f.write("self.recall(alternatives = pickle.loads( base64.standard_b64decode('")
f.write( base64.standard_b64encode(pickle.dumps(self.alternatives())).decode('utf8') )
f.write("')))\n")

f.write("self.covariance_matrix = numpy.loads( base64.standard_b64decode('")
f.write( base64.standard_b64encode(self.covariance_matrix.dumps()).decode('utf8') )
f.write("'))\n")
Expand Down Expand Up @@ -612,7 +623,6 @@ def save(self, filename, overwrite=False, spool=True, report=False, report_cats=
f.write("self.{} = {!r}\n".format(a,getattr(self,a)))
else:
if not aliens_found:
import pickle
f.write("import pickle\n")
aliens_found = True
try:
Expand Down Expand Up @@ -663,9 +673,11 @@ def copy(self, other="@@@"):
exec(code)
return self

def recall(self, nCases=None):
def recall(self, nCases=None, alternatives=None):
if nCases is not None:
self._nCases_recall = nCases
if alternatives is not None:
self._alternatives_recall = alternatives

def __utility_get(self):
return _core.Model2_utility_get(self)
Expand Down Expand Up @@ -925,15 +937,15 @@ def new_nest(self, nest_name=None, param_name="", branch=None, **kwargs):
new_node = new_nest

def report_(self, cats='*', **kwargs):
with XHTML('temp', quickhead=self, **kwargs) as f:
with XHTML('temp', quickhead=self, embed_model=self, **kwargs) as f:
f << self.report(cats=cats, style='xml')

def report_1(self, filename="/tmp/larchreport.html", **kwargs):
from .util.filemanager import next_stack
print("from filename",filename)
filename = next_stack(filename,suffix='html')
print("to filename", filename)
with XHTML(filename, quickhead=self, **kwargs) as f:
with XHTML(filename, quickhead=self, embed_model=self, **kwargs) as f:
f << self.report(cats='*', style='xml')


Expand Down
2 changes: 1 addition & 1 deletion py/model_reporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def report(self, style, *args, filename=None, tempfile=False, **kwargs):
if filename is None and tempfile==False:
return rpt
else:
f = XHTML("temp" if tempfile else filenext(filename), quickhead=self, **kwargs)
f = XHTML("temp" if tempfile else filenext(filename), quickhead=self, embed_model=self, **kwargs)
f << rpt
f.dump()
return f
Expand Down

0 comments on commit 57c2437

Please sign in to comment.