From a2cf1d0b456f3c80ea17a815961ec6f319de73e5 Mon Sep 17 00:00:00 2001 From: Aditya Nambiar Date: Tue, 17 Sep 2024 17:47:34 -0700 Subject: [PATCH] lambda: Fix bug for using lambdas in jupyter notebook (#563) --- fennel/CHANGELOG.md | 3 +++ fennel/internal_lib/to_proto/source_code.py | 18 ++++++++++++++---- pyproject.toml | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/fennel/CHANGELOG.md b/fennel/CHANGELOG.md index 64ec5542..7d3d4ce1 100644 --- a/fennel/CHANGELOG.md +++ b/fennel/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## [1.5.23] - 2024-09-17 +- Fix bug for using lambdas in jupyter notebooks + ## [1.5.22] - 2024-09-12 - Add casting to pyarrow for using expression in assign. diff --git a/fennel/internal_lib/to_proto/source_code.py b/fennel/internal_lib/to_proto/source_code.py index f5586676..2017defb 100644 --- a/fennel/internal_lib/to_proto/source_code.py +++ b/fennel/internal_lib/to_proto/source_code.py @@ -321,10 +321,20 @@ def check_ambiguous_lambda( """ # Get the next line and append to lambda text next_line = "" - with open(lambda_func.__code__.co_filename, "r") as f: - lines = f.readlines() - if line_num < len(lines): - next_line = lines[line_num].strip() + try: + with open(lambda_func.__code__.co_filename, "r") as f: + lines = f.readlines() + if line_num < len(lines): + next_line = lines[line_num].strip() + except Exception: + # In jupyter notebook, we don't have co_filename available. + # So we are using fennel_get_source to get the source code and try to find the next line. + # This is not perfect, and might not work for all cases. + src_code = fennel_get_source(lambda_func) + num_lines = src_code.count("\n") + if num_lines <= 1: + return + next_line = src_code.split("\n")[1] # No Next line found if next_line == "": diff --git a/pyproject.toml b/pyproject.toml index 99dda886..43ede538 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fennel-ai" -version = "1.5.22" +version = "1.5.23" description = "The modern realtime feature engineering platform" authors = ["Fennel AI "] packages = [{ include = "fennel" }]