biolab / orange3

šŸŠ :bar_chart: :bulb: Orange: Interactive data analysis
https://orangedatamining.com
Other
4.85k stars 1.01k forks source link

Select Rows with TimeVariable fails #5648

Closed mw25 closed 1 year ago

mw25 commented 3 years ago

What's wrong?

When the Select Rows gets a TimeVariable converted from numeric the following error message appears and the spinbox (DateTimeWidget?) in the widget is arranged strangely:

image


Exception:
AttributeError: 'DateTimeWidget' object has no attribute 'min_datetime'
Module:
Orange.widgets.data.owselectrows:890
Widget Name:
Select Rows
Widget Module:
Orange.widgets.data.owselectrows:566
Widget Scheme:
[...]
Version:
3.30.1
Environment:
Python 3.7.9 on Windows 10 10.0.18362 AMD64
Installed Packages:
[...]
Stack Trace:
Traceback (most recent call last):
  File "D:\orange3\venv\lib\site-packages\orangecanvas\scheme\signalmanager.py", line 1024, in __process_next
    if self.__process_next_helper(use_max_active=True):
  File "D:\orange3\venv\lib\site-packages\orangecanvas\scheme\signalmanager.py", line 1062, in __process_next_helper
    self.process_node(selected_node)
  File "D:\orange3\venv\lib\site-packages\orangecanvas\scheme\signalmanager.py", line 690, in process_node
    self.send_to_node(node, signals_in)
  File "D:\orange3\venv\lib\site-packages\orangewidget\workflow\widgetsscheme.py", line 824, in send_to_node
    self.process_signals_for_widget(node, widget, signals)
  File "D:\orange3\venv\lib\site-packages\orangewidget\workflow\widgetsscheme.py", line 838, in process_signals_for_widget
    process_signals_for_widget(widget, signals, workflow)
  File "C:\Program Files\Python37\lib\functools.py", line 840, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "D:\orange3\venv\lib\site-packages\orangewidget\workflow\widgetsscheme.py", line 939, in process_signals_for_widget
    process_signal_input(input_meta, widget, signal, workflow)
  File "C:\Program Files\Python37\lib\functools.py", line 840, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "D:\orange3\venv\lib\site-packages\orangewidget\workflow\widgetsscheme.py", line 903, in process_signal_input_default
    input, widget, value, key=key, index=index_local
  File "C:\Program Files\Python37\lib\functools.py", line 840, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "D:\orange3\venv\lib\site-packages\orangewidget\utils\signals.py", line 650, in set_input_helper
    handler(*args)
  File "D:\orange3\venv\lib\site-packages\orangewidget\utils\signals.py", line 201, in summarize_wrapper
    method(widget, value)
  File "D:\orange3\venv\lib\site-packages\Orange\widgets\data\owselectrows.py", line 566, in set_data
    self.add_row()
  File "D:\orange3\venv\lib\site-packages\Orange\widgets\data\owselectrows.py", line 310, in add_row
    condition_type, condition_value)
  File "D:\orange3\venv\lib\site-packages\Orange\widgets\data\owselectrows.py", line 372, in set_new_operators
    self.set_new_values(oper_combo, adding_all, selected_values)
  File "D:\orange3\venv\lib\site-packages\Orange\widgets\data\owselectrows.py", line 522, in set_new_values
    w.set_datetime(lc[0])
  File "D:\orange3\venv\lib\site-packages\Orange\widgets\data\owselectrows.py", line 890, in set_datetime
    date_time = self.min_datetime
AttributeError: 'DateTimeWidget' object has no attribute 'min_datetime'

Local Variables:
OrderedDict([('date_time', ''),
             ('self',
              <Orange.widgets.data.owselectrows.DateTimeWidget object at 0x000002B9DBDB5168>)])

How can we reproduce the problem?

Take a numeric variable and convert it to a TimeVariable. (e.g. Paint a point in Paint Data, convert the x variable in Edit Domain to Time-Type). Put the table at the Select Rows input.

What's your environment?

ajdapretnar commented 3 years ago

Thank you for reporting this! Nice find!

For the rest: one doesn't even need Paint. It fails even when reinterpreting sepal length as Time and using Select Rows.

thocevar commented 2 years ago

The problem is in the Edit Domain widget, which constructs the Time Variable from Continuous Variable without specifying the have_date and have_time properties.

https://github.com/biolab/orange3/blob/2c29c7a711cebfe33c8d378571546d7f88df7c61/Orange/widgets/data/oweditdomain.py#L2713

It is not obvious how to interpret continuous values as time:

mw25 commented 2 years ago

The same problem with File Widget: Open iris.tab in File Widget, change sepal length to datetime and use Select Rows.

I think it is the same problem (have_date and have_time is not specified) at this code location: https://github.com/biolab/orange3/blob/2c29c7a711cebfe33c8d378571546d7f88df7c61/Orange/widgets/utils/domaineditor.py#L364

If my opinion on the interpretation of the values counts:

Intuitively, I would interpret a time variable with numeric values without further information as seconds, because that is the SI unit. Another interpretation could be helpful or annoying. But if it is done, why only years? What about the other possible formats, which are defined in TimeVariable and could theoretically be numeric:

Of course it would be nice if Orange would automatically detect these formats, but manually it is already possible now: For example, if you want to convert a numeric variable with years to time (or other formats like 20200101, 20200102, ...), you could first convert it to text and then to time. This is not very intuitive and user-friendly, but it works. A numeric variable (e.g. 2010, 2011, 2012, ...) that is converted to time and mistakenly interpreted as years or days cannot be easily converted back to seconds, as far as I know.