-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[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
base: develop
Are you sure you want to change the base?
Conversation
✅ PR preview is ready!
|
There was a problem hiding this 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)
🎉 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) |
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:pandas.io.formats.style.Styler.map
is missing pandas-dev/pandas-stubs#1226 -> fix is merged, waiting for a release.columns
on existingDataFrame
does not accept "List[str]" pandas-dev/pandas-stubs#73 -> fix is merged in mypy, waiting for mypy releasepandas-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.