parquet - Im using polars library, but I'm getting 'NameError: name 'PyLazyFrame' is not defined

admin2025-04-17  4

Im trying to get data from a parquet file using SQL syntax.

The code:

import polars as pl

# Ensure the variables are defined
parquet_file = r'C:\Users\Kperez\Documents\md_curated_20250115.parquet'
date = "2024-12-13"

df3 = pl.read_parquet(parquet_file)

# Register the DataFrame as a table and execute the SQL query
ctx = pl.SQLContext()
ctx.register("data", df3)
result = ctx.execute(f"SELECT Identifier, IQ_CLOSEPRICE FROM data where Date = '{date}'").collect()
print(result)

But I got an error like this:

NameError: name 'PyLazyFrame' is not defined

View:

Any ideas?

Im trying to get data from a parquet file using SQL syntax.

The code:

import polars as pl

# Ensure the variables are defined
parquet_file = r'C:\Users\Kperez\Documents\md_curated_20250115.parquet'
date = "2024-12-13"

df3 = pl.read_parquet(parquet_file)

# Register the DataFrame as a table and execute the SQL query
ctx = pl.SQLContext()
ctx.register("data", df3)
result = ctx.execute(f"SELECT Identifier, IQ_CLOSEPRICE FROM data where Date = '{date}'").collect()
print(result)

But I got an error like this:

NameError: name 'PyLazyFrame' is not defined

View:

Any ideas?

Share Improve this question edited Jan 30 at 19:07 jqurious 22.2k5 gold badges20 silver badges39 bronze badges asked Jan 30 at 19:05 qarly_blueqarly_blue 4204 silver badges8 bronze badges 1
  • 1 I used 'pip install polars' but the problem was the python version. Thank you! – qarly_blue Commented Jan 30 at 19:47
Add a comment  | 

2 Answers 2

Reset to default 1

The problem was Python version

Polars doesn't work with Python 3.9, when I changed to Python 3.13 (latest at this moment) my code was executed successfully:

View:

The latest version of polars i.e. 1.21.0 actually supports Python 3.9 - 3.13 and has wheels for Python 3.9+ on all major platforms.

This seems to be an issue with your Windows OS and specific polars version. As was quoted in the linked issue:

This error message only appears on Windows 7 systems. It works fine on Windows 11 systems. Based on my testing, installing a version higher than 0.20.16 on Windows 7 results in this error, while installing version 0.20.16 works correctly.

转载请注明原文地址:http://www.anycun.com/QandA/1744896107a89153.html