Skip to content
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

usage.py failing: minimum polars version required? #4

Open
abubelinha opened this issue Mar 5, 2024 · 3 comments
Open

usage.py failing: minimum polars version required? #4

abubelinha opened this issue Mar 5, 2024 · 3 comments

Comments

@abubelinha
Copy link

abubelinha commented Mar 5, 2024

Coming from #3 , where I tried installation on two different Windows machines.
Both of them have now polars and polars-fuzzy-match v. 0.1.3

  • On Python 3.9 machine (Windows 10 64 bits), I couldn't run usage.py example. This line raised error:

from polars_fuzzy_match import fuzzy_match_score

c:\python39\python polarex.py
Traceback (most recent call last):
  File "c:\python\polarex.py", line 78, in <module>
    polarsfm_usage(); sys.exit()
  File "c:\python\polarex.py", line 11, in polarsfm_usage
    from polars_fuzzy_match import fuzzy_match_score
  File "c:\python39\lib\site-packages\polars_fuzzy_match\__init__.py", line 4, in <module>
    from polars.type_aliases import IntoExpr
ModuleNotFoundError: No module named 'polars.type_aliases'
  • On Python 3.8 machine (Windows 7 64 bits) the example runs without errors:
c:\Python38\python polarex.py
shape: (2, 2)
┌─────────────┬───────┐
│ strs        ┆ score │
│ ---         ┆ ---   │
│ str         ┆ u32   │
╞═════════════╪═══════╡
│ foo quz BAR ┆ 88    │
│ baaarfoo    ┆ 74    │
└─────────────┴───────┘

  • The code:
def polarsfm_usage():
	""" Taken from https://github.com/bnm3k/polars-fuzzy-match/blob/master/examples/usage.py """
	import polars as pl
	from polars_fuzzy_match import fuzzy_match_score


	df = pl.DataFrame(
		{
			'strs': ['foo', 'foo quz BAR', 'baaarfoo', 'quz'],
		}
	)
	pattern = 'bar'
	out = (
		df.with_columns(
			score=fuzzy_match_score(
				pl.col('strs'),
				pattern,
			)
		)
		.filter(pl.col('score').is_not_null())
		.sort(by='score', descending=True)
	)
	print(out)

What could be the reason for this difference?

Both machines can run this very basic polars script without errors:

import polars as pl
localcsv = "sample.csv"
df = pl.read_csv(localcsv, infer_schema_length=2, ignore_errors=True)
print(df.sample(25))
print(df.describe())

Thanks a lot in advance
@abubelinha

@abubelinha
Copy link
Author

abubelinha commented Mar 5, 2024

Update:

Now I recall a problem when I installed polars yesterday in Python 3.8 / Windows 7.
Although pip installation was completed without errors, importing polars raised an error (something I don't recall, related to CPU) and suggesting to try this package instead (and that's what I did):
pip install polars-lts-cpu
After doing that, polars example worked (and polars-fuzzy-match usage.py example works too).

My installation of polars in Python 3.9 / Windows 10 did not raise such polars importing error, so that machine has the normal polars pip package, and my polars read_csv example script works good.

Oddly, the "normal" installation is the one where polars-fuzzy-match usage.py example fails.

@abubelinha
Copy link
Author

I guess this was related to polars version, which was older in my Python 3.9 machine.
Something around 0.16? ... sorry I didn't annotate it, but I upgraded polars to 0.20.13 and now polars-fuzzy-match usage.py example is working.

Perhaps polars-fuzzy-match installation could take care of this? (in case you can confirm a minimum polars version is required)

@abubelinha abubelinha changed the title different behaviours of usage.py example different behaviours of usage.py example: minimum polars version required? Mar 5, 2024
@abubelinha abubelinha changed the title different behaviours of usage.py example: minimum polars version required? usage.py failing: minimum polars version required? Mar 5, 2024
@bnm3k
Copy link
Owner

bnm3k commented Mar 5, 2024

Yeah, I was about to add that if the issue is that polars.type_aliases cannot be imported then the problem's most likely with polars rather than the plugin. But seems you've figured it out :)

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

No branches or pull requests

2 participants