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
Typeconversion from float to str #14
Conversation
Gtk.ListStore in Line 542 is initailized with values str.
while giving float, following errors if click on "import-freespace" or "import-journal" button.
Traceback (most recent call last):
File "/usr/share/sugar/activities/analyzeJournal/activity.py", line 443, in __import_freespace_cb
self._graph_from_reader(reader)
File "/usr/share/sugar/activities/analyzeJournal/activity.py", line 425, in _graph_from_reader
self._add_value(None, label=row[0], value=float(row[1]))
File "/usr/share/sugar/activities/analyzeJournal/activity.py", line 432, in _add_value
pos = self.labels_and_values.add_value(label, value)
File "/usr/share/sugar/activities/analyzeJournal/activity.py", line 582, in add_value
_iter = self.model.insert(path, [label, value])
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 1007, in insert
return self._do_insert(position, row)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 988, in _do_insert
row, columns = self._convert_row(row)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 900, in _convert_row
result.append(self._convert_value(cur_col, value))
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 914, in _convert_value
return GObject.Value(self.get_column_type(column), value)
File "/usr/lib/python3/dist-packages/gi/overrides/GObject.py", line 210, in __init__
self.set_value(py_value)
File "/usr/lib/python3/dist-packages/gi/overrides/GObject.py", line 249, in set_value
raise TypeError("Expected string but got %s%s" %
TypeError: Expected string but got 10590.3046875<class 'float'>
Traceback (most recent call last):
File "/usr/share/sugar/activities/analyzeJournal/activity.py", line 447, in __import_journal_cb
self._graph_from_reader(reader)
File "/usr/share/sugar/activities/analyzeJournal/activity.py", line 425, in _graph_from_reader
self._add_value(None, label=row[0], value=float(row[1]))
File "/usr/share/sugar/activities/analyzeJournal/activity.py", line 432, in _add_value
pos = self.labels_and_values.add_value(label, value)
File "/usr/share/sugar/activities/analyzeJournal/activity.py", line 582, in add_value
_iter = self.model.insert(path, [label, value])
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 1007, in insert
return self._do_insert(position, row)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 988, in _do_insert
row, columns = self._convert_row(row)
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 900, in _convert_row
result.append(self._convert_value(cur_col, value))
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 914, in _convert_value
return GObject.Value(self.get_column_type(column), value)
File "/usr/lib/python3/dist-packages/gi/overrides/GObject.py", line 210, in __init__
self.set_value(py_value)
File "/usr/lib/python3/dist-packages/gi/overrides/GObject.py", line 249, in set_value
raise TypeError("Expected string but got %s%s" %
TypeError: Expected string but got 25.0<class 'float'>
| @@ -579,7 +579,7 @@ def add_value(self, label, value): | |||
| elif selected: | |||
| path = int(str(self.model.get_path(selected))) + 1 | |||
| try: | |||
| _iter = self.model.insert(path, [label, value]) | |||
| _iter = self.model.insert(path, [label, str(value)]) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure it should be changed to str here, instead of TypeError Exception handling? Also I suggest you mention just the error and some part of the traceback in the commit message than copy pasting the entire traceback :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah actually in https://github.com/sugarlabs/AnalyzeJournal/pull/14/files#diff-03091df2633029b2c2893b03883f5296R542 , it is initialised with str. We can try Exception handling if it is not reproducible by your test system. Can you tell about your test system( earlier one also in case it is changed) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @JuiP. The exception handling does take care of the typecast that has been introduced in the try block
|
@Saumya-Mishra9129 Could you please explain how do I reproduce the error? |
Error is reproducible just by clicking on |
|
Oh, I tested again, I still don't get the error I'm using a debian 10 buster VM to test |
I also tested , error is not reproduced with debian 10 buster but with Ubuntu I can get. |
|
Interesting! |
|
Thanks for reviewing!! I will made necessary changes.
…On Thu 25 Jun, 2020, 12:32 PM Rahul Bothra, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In activity.py
<#14 (comment)>
:
> @@ -579,7 +579,7 @@ def add_value(self, label, value):
elif selected:
path = int(str(self.model.get_path(selected))) + 1
try:
- _iter = self.model.insert(path, [label, value])
+ _iter = self.model.insert(path, [label, str(value)])
I agree with @JuiP <https://github.com/JuiP>. The exception handling does
take care of the typecast that has been introduced in the try block
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKZH63PEFJY5SRLQV5GPTGTRYLY7VANCNFSM4OFBIXIQ>
.
|
|
On the face of it, converting the value from float to string is contradictory to it being converted to float by ChartData contains a Gtk.ListStore with data type signature (str, str), not (str, float), but the It seems likely that a more correct solution is to recognise that TypeError is returned by Gtk.ListStore on Python 3, and ValueError on Python 2. If so, the solution will be to change the name of the exception. It isn't clear from the commit message if this is understood; there's no description of the problem and how it is solved. There's only a couple of tracebacks. |
I don't agree with this. Both TypeError and ValueError has different meanings in Python3. Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError However a ValueError is raised when - Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value
Line 582 in 2574bb0
Line 584 in 2574bb0
I agree but these both lines uses different methods - insert and append , they both have different meanings and signifies why a ValueError is used. Workaround could be using another exception handler for TypeError which should convert float to str. |
|
Please look at comment-#13 |
|
@JuiP, thanks, I agree. |
I agree. We can close this PR now. |
@quozl @JuiP Please review.