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

lambda: Fix bug for using lambdas in jupyter notebook #563

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fennel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
18 changes: 14 additions & 4 deletions fennel/internal_lib/to_proto/source_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment for when we expect the exception to happen what we're trying to do? Is the behavior desirable in general or only if we're operating in a notebook environment? If the latter, can we somehow check for that if this is not always the right thing to do?

# 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 == "":
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <developers@fennel.ai>"]
packages = [{ include = "fennel" }]
Expand Down
Loading