refactor: Cache, reuse Implementation._backend_version#2764
Merged
MarcoGorelli merged 34 commits intomainfrom Jul 3, 2025
Merged
refactor: Cache, reuse Implementation._backend_version#2764MarcoGorelli merged 34 commits intomainfrom
Implementation._backend_version#2764MarcoGorelli merged 34 commits intomainfrom
Conversation
I shoul've caught that in review (#2620 (comment))
Mentioned in - #2620 (comment) - #1657 (reply in thread) Now that validation happens **within** that call, we can remove it from every `Series`, `DataFrame`, `LazyFrame` constructor and stop passing it around
`lazy()` and `collect()` between backends is really the only place we might need to preserve the current checks
We don't need the version anymore https://github.com/narwhals-dev/narwhals/actions/runs/15982913249/job/45081217959?pr=2764
Now `mypy` understands the same error as `pyright` 😏
- Seemed the easiest way to get coverage - Will split into another PR - https://ibis-project.org/reference/expression-tables#ibis.memtable
Was broken on windows > UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 21406: character maps to <undefined>
Implementation._backend_versionImplementation._backend_version
Implementation._backend_versionImplementation._backend_version
MarcoGorelli
reviewed
Jul 3, 2025
Member
MarcoGorelli
left a comment
There was a problem hiding this comment.
generally on board, probably needs a merge
Comment on lines
-491
to
+480
| if ( | ||
| self._implementation | ||
| in {Implementation.PYSPARK, Implementation.PYSPARK_CONNECT} | ||
| and (pyspark := get_pyspark()) is not None | ||
| and parse_version(pyspark) < (3, 4) | ||
| ): # pragma: no cover | ||
| if self._implementation in { | ||
| Implementation.PYSPARK, | ||
| Implementation.PYSPARK_CONNECT, | ||
| } and Implementation.PYSPARK._backend_version() < (3, 4): # pragma: no cover |
Member
|
thanks - shiny failure is unrelated (and now resolved), i'd say let's wait for this to turn green then we can ship it |
dangotbanned
added a commit
that referenced
this pull request
Jul 29, 2025
Added the same for `_polars.utils` in #2764
This was referenced Aug 27, 2025
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.
What type of PR is this? (check all applicable)
Related issues
Implementation.to_native_namespace#2620 (comment)Compliant*methods #2713_backend_versionis no longer specified inCompliant*protocolsChecklist
If you have comments or can explain your changes, please do so below
The diff is big, but the changes boil down to:
Implementation._backend_versionis now cached (5fac883)The validation of
backend_versionoccurs before returning the cached value.Therefore, if we manage to access it - it must be valid - so we don't need to repeat that validation for every
DataFrame,LazyFrame,Series.In the cases where we might be importing a backend for the first time (
lazy|collect), the version will either beTasks
Most changes are factoring-out
_backend_versionfromCompliant*to useImplementation._backend_version()instead:Eager*,PandasLike*,Arrow*classesLazy*,Dask*,DuckDB*,Ibis*,SparkLike*Compliant*Polars*narwhals/_*/utils.py"utf-8"encoding for windows #2770DataFrame().lazy("ibis")#2771