Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Nov 7, 2024
1 parent a721854 commit faa454e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions panel/io/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,18 @@ def _polars_combine_hash_expr(columns):
def _polars_hash(obj):
import polars as pl

type_hash = type(obj).__name__.encode()
hash_type = type(obj).__name__.encode()

if isinstance(obj, pl.Series):
obj = obj.to_frame()

columns = obj.collect_schema().names()
hash_columns = _container_hash(columns)

# LazyFrame does not support len and sample
if type_hash != b"LazyFrame" and len(obj) >= _DATAFRAME_ROWS_LARGE:
if hash_type != b"LazyFrame" and len(obj) >= _DATAFRAME_ROWS_LARGE:
obj = obj.sample(n=_DATAFRAME_SAMPLE_SIZE, seed=0)
elif type_hash == b"LazyFrame":
elif hash_type == b"LazyFrame":
count = obj.select(pl.col(columns[0]).count()).collect().item()
if count >= _DATAFRAME_ROWS_LARGE:
obj = obj.select(pl.all().sample(n=_DATAFRAME_SAMPLE_SIZE, seed=0))
Expand All @@ -184,8 +185,7 @@ def _polars_hash(obj):
hash_data = hash_data.collect()
hash_data = _int_to_bytes(hash_data.item())

hash_columns = _container_hash(columns)
return type_hash + hash_data + hash_columns
return hash_type + hash_data + hash_columns

def _numpy_hash(obj):
h = hashlib.new("md5")
Expand Down

0 comments on commit faa454e

Please sign in to comment.