Repository navigation
Fix compatibility with pandas 3 - #58
Open
Klapperhorn wants to merge 1 commit into
Open
Klapperhorn wants to merge 1 commit into
Klapperhorn wants to merge 1 commit into
Conversation
- likert_counts: drop the `copy` keyword from set_axis (deprecated in pandas 3, Pandas4Warning) and the string version comparison - route all element-wise calls through _map_elements(), which uses DataFrame.map (pandas >= 2.1) and falls back to applymap; this also fixes the fallback in likert_response, which called .map twice - update module docstring (applymap -> map) - add tests/test_pandas_compat.py (counts, percentages, likert_response, plotting; deprecation warnings are treated as errors) - CI: Python 3.9-3.13 with latest pandas, plus pandas 2.1 and 2.2; bump actions to checkout@v4 / setup-python@v5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pandas 3.0 removed
DataFrame.applymap, so the current PyPI release (0.5.0) fails withAttributeError: 'DataFrame' object has no attribute 'applymap'. Master already switched toDataFrame.map(ce15502), but that change has not been released yet, and a few smaller things remain:likert_countscalledset_axis(..., copy=True). In pandas 3 thecopykeyword is deprecated (Pandas4Warning, to be removed in pandas 4), and the string comparisonpd.__version__ >= "1.5.0"used to choose the branch is fragile.set_axisreturns a new object by default since pandas 1.0, so the call is now justdf.set_axis(new_labels, axis=1).applymapfallback inlikert_responsecalled.mapin both branches, so pandas < 2.1 would still fail there. All three element-wise calls now go through a small helper,_map_elements(), which usesDataFrame.mapwhen available andapplymapotherwise. This also avoidsexcept AttributeErroraround user callbacks.scores.map(int).map(str)).Tests:
tests/test_pandas_compat.pycoverslikert_counts(DataFrame, Series, NaN,stringdtype, wrapping, invalid values, numeric scales),likert_percentages(including a non-integer index),likert_response, and plotting with the Agg backend. pandas/NumPy deprecation warnings are turned into errors inside these tests.ubuntu-latest.Tested locally: pandas 3.1.1 (Python 3.12, NumPy 2.5, Matplotlib 3.11), pandas 2.2.3 and pandas 2.1.4. All 20 tests pass. The
applymapfallback was also checked by simulating pandas < 2.1.I've used plot-likert a lot over the last few years, both for analysing survey data in my research and in teaching, and it has saved me and my students a lot of time. Thank you for creating and maintaining it! A release with this fix (e.g. 0.5.1) would help everyone who has moved to pandas 3.
🤖 Generated with Claude Code