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

[ENH] Feature Constructor: Enable comprehensions and lambdas in expressions #6272

Conversation

ales-erjavec
Copy link
Contributor

Issue

Fixes #6265

Description of changes

Enable comprehensions and lambdas in expressions

Includes
  • Code changes
  • Tests
  • Documentation

@ales-erjavec ales-erjavec force-pushed the owfeatureconstructor-name-bindings-expressions branch from 1ea713d to 1d125d8 Compare December 23, 2022 12:55
@codecov
Copy link

codecov bot commented Dec 23, 2022

Codecov Report

Merging #6272 (1d125d8) into master (acb7120) will increase coverage by 0.01%.
The diff coverage is 95.27%.

❗ Current head 1d125d8 differs from pull request most recent head 6e7fc2c. Consider uploading reports for the commit 6e7fc2c to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6272      +/-   ##
==========================================
+ Coverage   86.70%   86.72%   +0.01%     
==========================================
  Files         316      316              
  Lines       68099    68124      +25     
==========================================
+ Hits        59048    59082      +34     
+ Misses       9051     9042       -9     

@janezd janezd self-assigned this Jan 6, 2023
@janezd
Copy link
Contributor

janezd commented Jan 6, 2023

It works for sum([x ** 2 for x in range(5)]), but sum(x ** 2 for x in range(5)) fails with

  File "/Users/janez/orange3/Orange/data/table.py", line 780, in from_table
    out = array_conv.get_columns(source, row_indices, n_rows,
  File "/Users/janez/orange3/Orange/data/table.py", line 317, in get_columns
    col_array = match_density(_compute_column(col, sourceri))
  File "/Users/janez/orange3/Orange/data/table.py", line 213, in _compute_column
    col = func(*args, **kwargs)
  File "/Users/janez/orange3/Orange/widgets/data/owfeatureconstructor.py", line 1267, in __call__
    return self.__call_table(table)
  File "/Users/janez/orange3/Orange/widgets/data/owfeatureconstructor.py", line 1291, in __call_table
    return np.asarray(y, dtype=self.dtype)
TypeError: float() argument must be a string or a number, not 'generator'

If this is difficult to fix, I'm OK with it - say so and I merge.

@ales-erjavec
Copy link
Contributor Author

ales-erjavec commented Jan 6, 2023

This is a problem with sum definition in the

https://github.com/biolab/orange3/blob/master/Orange/widgets/data/owfeatureconstructor.py#L1214

    ...
    "sum": lambda *args: np.sum(args),

i.e.

sum = lambda *args: np.sum(args)
print(sum(x ** 2 for x in range(5)))
<generator object <genexpr> at 0x1359e5770>

I guess the builtin overrides should be removed?

@janezd
Copy link
Contributor

janezd commented Jan 6, 2023

I guess the builtin overrides should be removed?

Yes.

@janezd janezd merged commit 90e9946 into biolab:master Jan 9, 2023
@ales-erjavec ales-erjavec deleted the owfeatureconstructor-name-bindings-expressions branch January 10, 2023 10:09
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

Successfully merging this pull request may close these issues.

Feature constructor: allow use of temporary variables
2 participants