Skip to content

[WIP] Activate type checking for pandas usage #11456

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

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented May 26, 2025

Describe your changes

Activates type checking for pandas API by installing pandas-stubs. However, there are a couple of issues before we can merge this:

  1. pandas.io.formats.style.Styler.map is missing pandas-dev/pandas-stubs#1226 -> fix is merged, waiting for a release.
  2. BUG: columns on existing DataFrame does not accept "List[str]" pandas-dev/pandas-stubs#73 -> fix is merged in mypy, waiting for mypy release
  3. pandas-stubs only supports Python >= 3.10 -> we need to wait until we remove 3.9 support (~ EOL October 2025) to be able to properly run this in our CI with all supported Python versions.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@lukasmasuch lukasmasuch requested a review from Copilot May 26, 2025 23:46
Copy link

github-actions bot commented May 26, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-11456/streamlit-1.45.1-py3-none-any.whl
🕹️ Preview app pr-11456.streamlit.app (☁️ Deploy here if not accessible)

Copy link
Contributor

@Copilot 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 pull request activates stricter type checking for pandas usage and improves type hinting across several modules. Key changes include the removal of ignore rules for pandas in mypy.ini, explicit generic type annotations for pandas types (e.g. pd.Series[Any]), and replacing implicit type casts with explicit ones in dataframe utility functions.

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
mypy.ini Removed pandas ignore rule to enable stricter type checking
lib/streamlit/runtime/caching/hashing.py Updated Series cast to include a generic type argument
lib/streamlit/elements/widgets/data_editor.py Improved type annotations and ensured column names are consistently cast to string
lib/streamlit/elements/lib/pandas_styler_utils.py Added type ignores for compatibility with pandas.Styler attributes
lib/streamlit/elements/lib/column_config_utils.py Introduced explicit generic typing for Series/Index parameters
lib/streamlit/elements/lib/built_in_chart_utils.py Changed map to apply for color conversion and added type ignore on column index assignment
lib/streamlit/dataframe_util.py Updated type casts, improved column selection with iloc, and refined type hints for better safety
lib/streamlit/components/v1/component_arrow.py Added generic type argument for Index and improved tuple-to-list mapping
Various e2e_playwright tests Converted generator expressions for column names to lists and added type hints for widget return values
Comments suppressed due to low confidence (3)

mypy.ini:68

  • Removing the ignore_missing_imports setting for pandas will enable stricter type checking. Please ensure that the correct type stubs for pandas are installed to avoid unexpected type errors.
-[mypy-pandas.*]
-ignore_missing_imports = true

lib/streamlit/elements/widgets/data_editor.py:875

  • Explicitly converting column names to strings ensures consistent handling, but please verify that all downstream consumers of the column config mapping expect string keys.
column_config_mapping, str(column_name), {"disabled": True}

lib/streamlit/elements/lib/built_in_chart_utils.py:643

  • Switching from map to apply ensures element‐wise function application. Please review the performance impact for large datasets to confirm that this change meets expectations.
df.loc[:, color_column] = df[color_column].apply(to_css_color)

Copy link
Contributor

snyk-io bot commented May 26, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy