Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad No-Metric Error #60

Open
gidden opened this issue Apr 30, 2015 · 6 comments
Open

Bad No-Metric Error #60

gidden opened this issue Apr 30, 2015 · 6 comments
Assignees
Milestone

Comments

@gidden
Copy link
Member

gidden commented Apr 30, 2015

This is non intuitive

$ cymetric cyclus.sqlite -e 'print(Foo[:])'
/home/gidden/.local/lib/python2.7/site-packages/cymetric/metrics.py:10: QAWarning: pyne.data is not yet QA compliant.
  from pyne import data
/home/gidden/.local/lib/python2.7/site-packages/cymetric/metrics.py:11: QAWarning: pyne.material is not yet QA compliant.
  import pyne.enrichment as enr
/home/gidden/.local/lib/python2.7/site-packages/cymetric/metrics.py:11: QAWarning: pyne.enrichment is not yet QA compliant.
  import pyne.enrichment as enr
Traceback (most recent call last):
  File "/home/gidden/.local/bin/cymetric", line 4, in <module>
    main()
  File "/home/gidden/.local/lib/python2.7/site-packages/cymetric/main.py", line 36, in main
    exec_code(ns.exec_code, db, write=ns.write)
  File "/home/gidden/.local/lib/python2.7/site-packages/cymetric/execution.py", line 217, in exec_code
    exec(code, glb, loc)
  File "<string>", line 1, in <module>
  File "/home/gidden/.local/lib/python2.7/site-packages/cymetric/execution.py", line 38, in __getitem__
    raise TypeError('ColumnProxy object {0!r} cannot be indexed'.format(self.name))
TypeError: ColumnProxy object 'Foo' cannot be indexed

Perhaps some logic could be added to catch a bad metric and print something more graceful.

@opotowsky opotowsky self-assigned this May 4, 2015
@opotowsky
Copy link
Member

So I think I should just change this (line 36, cymetric/execution.py):

def __getitem__(self, *args, **kwargs):
    """Stub function that prevents ColumnProxies from being indexed."""
    raise TypeError('ColumnProxy object {0!r} cannot be indexed'.format(self.name))

to say something else? I'm not sure what. "cannot be found"?

@gidden
Copy link
Member Author

gidden commented May 6, 2015

there is probably somewhere higher up that tries to do something like
evaluator[metric] that you could wrap a try/except clause around

On Wed, May 6, 2015 at 4:49 PM, opotowsky [email protected] wrote:

So I think I should just change this (line 36, cymetric/execution.py):

def getitem(self, _args, *_kwargs):
"""Stub function that prevents ColumnProxies from being indexed."""
raise TypeError('ColumnProxy object {0!r} cannot be indexed'.format(self.name))

to say something else? I'm not sure what. "cannot be found"?


Reply to this email directly or view it on GitHub
#60 (comment).

Matthew Gidden, Ph.D.
Postdoctoral Associate, Nuclear Engineering
The University of Wisconsin -- Madison
Ph. 225.892.3192

@opotowsky
Copy link
Member

So in evaluator.py there is:

 42    def get_metric(self, metric):
 43         """Checks if metric is already in the registry; adds it if not."""
 44         if metric not in self.metrics:
 45             self.metrics[metric] = METRIC_REGISTRY[metric](self.db)
 46         return self.metrics[metric]
 47 
 48     def eval(self, metric, conds=None):
 49         """Evalutes a metric with the given conditions."""
 50         rawkey = (metric, conds if conds is None else frozenset(conds))
 51         if rawkey in self.rawcache:
 52             return self.rawcache[rawkey]
 53         m = self.get_metric(metric)
 54         series = []
 55         for dep in m.dependencies:
 56             d = self.eval(dep[0], conds=conds)
 57             s = None if d is None else raw_to_series(d, dep[1], dep[2])
 58             series.append(s)
 59         raw = m(series=series, conds=conds, known_tables=self.known_tables)
 60         if raw is None:
 61             return raw
 62         self.rawcache[rawkey] = raw
 63         # write back to db
 64         if (m.name in self.known_tables) or (not self.write):
 65             return raw
 66         rec = self.recorder
 67         rawd = raw.to_dict(outtype='list')
 68         for i in range(len(raw)):
 69             d = rec.new_datum(m.name)
 70             for field, dbtype, shape in m.schema:
 71                 fname = m.schema.byte_names[field]
 72                 val = rawd[str(field)][i]
 73                 d = d.add_val(fname, val, dbtype=dbtype, shape=shape)
 74             d.record()
 75         self.known_tables.add(m.name)
 76         return raw

Should I do the try/except clause around line 45?

@opotowsky opotowsky added this to the v1.4 milestone May 6, 2015
@gidden
Copy link
Member Author

gidden commented May 6, 2015

The short answer is: you can try it and find out using the same example in
the issue =)
The perhaps slightly longer answer is: I don't know and would have to dig
myself because I don't intimately know the code base =/

On Wed, May 6, 2015 at 5:30 PM, opotowsky [email protected] wrote:

So in evaluator.py there is:

42 def get_metric(self, metric):
43 """Checks if metric is already in the registry; adds it if not."""
44 if metric not in self.metrics:
45 self.metrics[metric] = METRIC_REGISTRYmetric
46 return self.metrics[metric]
47
48 def eval(self, metric, conds=None):
49 """Evalutes a metric with the given conditions."""
50 rawkey = (metric, conds if conds is None else frozenset(conds))
51 if rawkey in self.rawcache:
52 return self.rawcache[rawkey]
53 m = self.get_metric(metric)
54 series = []
55 for dep in m.dependencies:
56 d = self.eval(dep[0], conds=conds)
57 s = None if d is None else raw_to_series(d, dep[1], dep[2])
58 series.append(s)
59 raw = m(series=series, conds=conds, known_tables=self.known_tables)
60 if raw is None:
61 return raw
62 self.rawcache[rawkey] = raw
63 # write back to db
64 if (m.name in self.known_tables) or (not self.write):
65 return raw
66 rec = self.recorder
67 rawd = raw.to_dict(outtype='list')
68 for i in range(len(raw)):
69 d = rec.new_datum(m.name)
70 for field, dbtype, shape in m.schema:
71 fname = m.schema.byte_names[field]
72 val = rawd[str(field)][i]
73 d = d.add_val(fname, val, dbtype=dbtype, shape=shape)
74 d.record()
75 self.known_tables.add(m.name)
76 return raw

Should I do the try/except clause around line 45?


Reply to this email directly or view it on GitHub
#60 (comment).

Matthew Gidden, Ph.D.
Postdoctoral Associate, Nuclear Engineering
The University of Wisconsin -- Madison
Ph. 225.892.3192

@opotowsky
Copy link
Member

Gotcha! Thanks. I'll try it out :-)

@opotowsky
Copy link
Member

Tried a number of ways with no luck, moving to 1.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants