Skip to content

Conversation

@mscolnick
Copy link
Contributor

@mscolnick mscolnick commented Sep 26, 2025

This migrates narwhals to v2. This is not breaking to user code and narwhals is perfectly backwards compatible.

This helps unblock more usage of our dataframe library, column explorer, and AI dataframe context for DuckDB and Ibis (which are better supported in v2)

@vercel
Copy link

vercel bot commented Sep 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Sep 30, 2025 3:38am

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates from narwhals v1 to narwhals v2, updating the API usage throughout the codebase while maintaining backward compatibility. The migration brings better support for DuckDB and Ibis dataframes, which enhances the functionality of the dataframe library, column explorer, and AI dataframe context.

  • Updates all imports from narwhals.stable.v1 to narwhals.stable.v2
  • Replaces deprecated API parameters like eager_or_interchange_only with eager_only
  • Adds backward compatibility support for v1 when needed for features not yet available in v2

Reviewed Changes

Copilot reviewed 26 out of 27 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pyproject.toml Updates narwhals dependency to v2.0.0+
marimo/_utils/narwhals_utils.py Core utility functions updated for v2 API with backward compatibility
marimo/_data/series.py Series processing functions updated to v2 decorators
marimo/_plugins/ui/_impl/tables/narwhals_table.py Main table manager updated with v2 types and backward compatibility for hist()
tests/_plugins/ui/_impl/test_altair_chart.py Test fixes for chart data handling changes
tests/_plugins/ui/_impl/tables/test_pandas_table.py Test assertion updated for null column unique count behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

import altair as alt

data = nw.from_native(pd.DataFrame({"values": [1, 2, 3]}))
data = pd.DataFrame({"values": [1, 2, 3]})
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

[nitpick] The variable name 'data' is misleading. This is creating a pandas DataFrame but the variable name suggests it could be any type of data. Consider renaming to 'df' or 'pandas_df' for clarity.

Copilot uses AI. Check for mistakes.
chart_spec = _get_chart_spec(
column_data=column_data,
# Downgrade to v1 since altair doesn't support v2 yet
# This is valiadted with our tests, so if the tests pass with this
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

Typo in comment: 'valiadted' should be 'validated'

Suggested change
# This is valiadted with our tests, so if the tests pass with this
# This is validated with our tests, so if the tests pass with this

Copilot uses AI. Check for mistakes.
Comment on lines +187 to +189
# If dtype has no timezone, but value has timezone, remove timezone without shifting
if dtype.time_zone is None and res.tzinfo is not None:
return res.replace(tzinfo=None)
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

Removing timezone information without shifting could lead to data inconsistency. The original logic with timezone shifting was more robust. Consider adding a comment explaining why this approach was chosen or validate that this change is intentional.

Suggested change
# If dtype has no timezone, but value has timezone, remove timezone without shifting
if dtype.time_zone is None and res.tzinfo is not None:
return res.replace(tzinfo=None)
# If dtype has no timezone, but value has timezone, shift to UTC before removing timezone info
if dtype.time_zone is None and res.tzinfo is not None:
# Shift to UTC before dropping tzinfo to avoid data inconsistency
return res.astimezone(datetime.timezone.utc).replace(tzinfo=None)

Copilot uses AI. Check for mistakes.
@mscolnick mscolnick merged commit 28d3ffb into main Sep 30, 2025
41 of 43 checks passed
@mscolnick mscolnick deleted the ms/narwhals-v2 branch September 30, 2025 13:15
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.

2 participants