From 77995c1d281feee6cf7dc9eea906676796702f7c Mon Sep 17 00:00:00 2001 From: vicky1999 Date: Tue, 1 Oct 2024 17:14:08 +0530 Subject: [PATCH] Comment Fixes --- daft/expressions/expressions.py | 2 +- daft/series.py | 9 +++++++++ docs/source/api_docs/expressions.rst | 1 - tests/series/test_cast.py | 16 ++++++++-------- ...ount_lengths.py => test_list_count_length.py} | 0 .../2-distributed-batch-inference.ipynb | 2 +- 6 files changed, 19 insertions(+), 11 deletions(-) rename tests/table/list/{test_list_count_lengths.py => test_list_count_length.py} (100%) diff --git a/daft/expressions/expressions.py b/daft/expressions/expressions.py index b3c2e41690..27fb746459 100644 --- a/daft/expressions/expressions.py +++ b/daft/expressions/expressions.py @@ -2941,7 +2941,7 @@ def lengths(self) -> Expression: Expression: a UInt64 expression which is the length of each list """ warnings.warn( - "This function will be deprecated from Daft version >= 0.3.5! Instead, please use 'length'", + "This function will be deprecated from Daft version >= 0.3.5! Instead, please use 'Expression.list.length'", category=DeprecationWarning, ) diff --git a/daft/series.py b/daft/series.py index 440d570b4a..d5156bf154 100644 --- a/daft/series.py +++ b/daft/series.py @@ -1,5 +1,6 @@ from __future__ import annotations +import warnings from typing import Any, Literal, TypeVar from daft.arrow_utils import ensure_array, ensure_chunked_array @@ -927,6 +928,14 @@ def iceberg_truncate(self, w: int) -> Series: class SeriesListNamespace(SeriesNamespace): def lengths(self) -> Series: + warnings.warn( + "This function will be deprecated from Daft version >= 0.3.5! Instead, please use 'Expression.list.length'", + category=DeprecationWarning, + ) + + return Series._from_pyseries(self._series.list_count(CountMode.All)) + + def length(self) -> Series: return Series._from_pyseries(self._series.list_count(CountMode.All)) def get(self, idx: Series, default: Series) -> Series: diff --git a/docs/source/api_docs/expressions.rst b/docs/source/api_docs/expressions.rst index 06fe1baa39..ec86e0bb5e 100644 --- a/docs/source/api_docs/expressions.rst +++ b/docs/source/api_docs/expressions.rst @@ -214,7 +214,6 @@ List :template: autosummary/accessor_method.rst Expression.list.join - Expression.list.lengths Expression.list.length Expression.list.get Expression.list.slice diff --git a/tests/series/test_cast.py b/tests/series/test_cast.py index cd0e74bdfa..b552aee20a 100644 --- a/tests/series/test_cast.py +++ b/tests/series/test_cast.py @@ -262,7 +262,7 @@ def test_cast_binary_to_fixed_size_binary(): assert casted.to_pylist() == [b"abc", b"def", None, b"bcd", None] -def test_cast_binary_to_fixed_size_binary_fails_with_variable_lengths(): +def test_cast_binary_to_fixed_size_binary_fails_with_variable_length(): data = [b"abc", b"def", None, b"bcd", None, b"long"] input = Series.from_pylist(data) @@ -368,7 +368,7 @@ def test_series_cast_python_to_list(dtype) -> None: assert t.datatype() == target_dtype assert len(t) == len(data) - assert t.list.lengths().to_pylist() == [3, 3, 3, 3, 2, 2, None] + assert t.list.length().to_pylist() == [3, 3, 3, 3, 2, 2, None] pydata = t.to_pylist() assert pydata[-1] is None @@ -397,7 +397,7 @@ def test_series_cast_python_to_fixed_size_list(dtype) -> None: assert t.datatype() == target_dtype assert len(t) == len(data) - assert t.list.lengths().to_pylist() == [3, 3, 3, 3, 3, 3, None] + assert t.list.length().to_pylist() == [3, 3, 3, 3, 3, 3, None] pydata = t.to_pylist() assert pydata[-1] is None @@ -426,7 +426,7 @@ def test_series_cast_python_to_embedding(dtype) -> None: assert t.datatype() == target_dtype assert len(t) == len(data) - assert t.list.lengths().to_pylist() == [3, 3, 3, 3, 3, 3, None] + assert t.list.length().to_pylist() == [3, 3, 3, 3, 3, 3, None] pydata = t.to_pylist() assert pydata[-1] is None @@ -448,7 +448,7 @@ def test_series_cast_list_to_embedding(dtype) -> None: assert t.datatype() == target_dtype assert len(t) == len(data) - assert t.list.lengths().to_pylist() == [3, 3, 3, None] + assert t.list.length().to_pylist() == [3, 3, 3, None] pydata = t.to_pylist() assert pydata[-1] is None @@ -473,7 +473,7 @@ def test_series_cast_numpy_to_image() -> None: assert t.datatype() == target_dtype assert len(t) == len(data) - assert t.list.lengths().to_pylist() == [12, 27, None] + assert t.list.length().to_pylist() == [12, 27, None] pydata = t.to_pylist() assert pydata[-1] is None @@ -495,7 +495,7 @@ def test_series_cast_numpy_to_image_infer_mode() -> None: assert t.datatype() == target_dtype assert len(t) == len(data) - assert t.list.lengths().to_pylist() == [4, 27, None] + assert t.list.length().to_pylist() == [4, 27, None] pydata = t.to_arrow().to_pylist() assert pydata[0] == { @@ -536,7 +536,7 @@ def test_series_cast_python_to_fixed_shape_image() -> None: assert t.datatype() == target_dtype assert len(t) == len(data) - assert t.list.lengths().to_pylist() == [12, 12, None] + assert t.list.length().to_pylist() == [12, 12, None] pydata = t.to_pylist() assert pydata[-1] is None diff --git a/tests/table/list/test_list_count_lengths.py b/tests/table/list/test_list_count_length.py similarity index 100% rename from tests/table/list/test_list_count_lengths.py rename to tests/table/list/test_list_count_length.py diff --git a/tutorials/delta_lake/2-distributed-batch-inference.ipynb b/tutorials/delta_lake/2-distributed-batch-inference.ipynb index 8462a74e0f..478980b9d9 100644 --- a/tutorials/delta_lake/2-distributed-batch-inference.ipynb +++ b/tutorials/delta_lake/2-distributed-batch-inference.ipynb @@ -138,7 +138,7 @@ "\n", "# Prune data\n", "df = df.limit(NUM_ROWS)\n", - "df = df.where(df[\"object\"].list.lengths() == 1)" + "df = df.where(df[\"object\"].list.length() == 1)" ] }, {