mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-12-14 08:37:42 +00:00
chore: removing Pipeline.draw() deprecation warnings (#9651)
* cleaning up tests * adding release notes
This commit is contained in:
parent
d059cf2c23
commit
8af4cf8b01
@ -47,12 +47,7 @@ from haystack.core.pipeline.component_checks import (
|
|||||||
is_any_greedy_socket_ready,
|
is_any_greedy_socket_ready,
|
||||||
is_socket_lazy_variadic,
|
is_socket_lazy_variadic,
|
||||||
)
|
)
|
||||||
from haystack.core.pipeline.utils import (
|
from haystack.core.pipeline.utils import FIFOPriorityQueue, _deepcopy_with_exceptions, parse_connect_string
|
||||||
FIFOPriorityQueue,
|
|
||||||
_deepcopy_with_exceptions,
|
|
||||||
args_deprecated,
|
|
||||||
parse_connect_string,
|
|
||||||
)
|
|
||||||
from haystack.core.serialization import DeserializationCallbacks, component_from_dict, component_to_dict
|
from haystack.core.serialization import DeserializationCallbacks, component_from_dict, component_to_dict
|
||||||
from haystack.core.type_utils import _type_name, _types_are_compatible
|
from haystack.core.type_utils import _type_name, _types_are_compatible
|
||||||
from haystack.marshal import Marshaller, YamlMarshaller
|
from haystack.marshal import Marshaller, YamlMarshaller
|
||||||
@ -690,9 +685,9 @@ class PipelineBase: # noqa: PLW1641
|
|||||||
}
|
}
|
||||||
return outputs
|
return outputs
|
||||||
|
|
||||||
@args_deprecated
|
|
||||||
def show(
|
def show(
|
||||||
self,
|
self,
|
||||||
|
*,
|
||||||
server_url: str = "https://mermaid.ink",
|
server_url: str = "https://mermaid.ink",
|
||||||
params: Optional[dict] = None,
|
params: Optional[dict] = None,
|
||||||
timeout: int = 30,
|
timeout: int = 30,
|
||||||
@ -735,24 +730,6 @@ class PipelineBase: # noqa: PLW1641
|
|||||||
If the function is called outside of a Jupyter notebook or if there is an issue with rendering.
|
If the function is called outside of a Jupyter notebook or if there is an issue with rendering.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Call the internal implementation with keyword arguments
|
|
||||||
self._show_internal(
|
|
||||||
server_url=server_url, params=params, timeout=timeout, super_component_expansion=super_component_expansion
|
|
||||||
)
|
|
||||||
|
|
||||||
def _show_internal(
|
|
||||||
self,
|
|
||||||
*,
|
|
||||||
server_url: str = "https://mermaid.ink",
|
|
||||||
params: Optional[dict] = None,
|
|
||||||
timeout: int = 30,
|
|
||||||
super_component_expansion: bool = False,
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Internal implementation of show() that uses keyword-only arguments.
|
|
||||||
|
|
||||||
ToDo: after 2.14.0 release make this the main function and remove the old one.
|
|
||||||
"""
|
|
||||||
if is_in_jupyter():
|
if is_in_jupyter():
|
||||||
from IPython.display import Image, display # type: ignore
|
from IPython.display import Image, display # type: ignore
|
||||||
|
|
||||||
@ -774,9 +751,9 @@ class PipelineBase: # noqa: PLW1641
|
|||||||
msg = "This method is only supported in Jupyter notebooks. Use Pipeline.draw() to save an image locally."
|
msg = "This method is only supported in Jupyter notebooks. Use Pipeline.draw() to save an image locally."
|
||||||
raise PipelineDrawingError(msg)
|
raise PipelineDrawingError(msg)
|
||||||
|
|
||||||
@args_deprecated
|
def draw(
|
||||||
def draw( # pylint: disable=too-many-positional-arguments
|
|
||||||
self,
|
self,
|
||||||
|
*,
|
||||||
path: Path,
|
path: Path,
|
||||||
server_url: str = "https://mermaid.ink",
|
server_url: str = "https://mermaid.ink",
|
||||||
params: Optional[dict] = None,
|
params: Optional[dict] = None,
|
||||||
@ -822,29 +799,6 @@ class PipelineBase: # noqa: PLW1641
|
|||||||
If there is an issue with rendering or saving the image.
|
If there is an issue with rendering or saving the image.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Call the internal implementation with keyword arguments
|
|
||||||
self._draw_internal(
|
|
||||||
path=path,
|
|
||||||
server_url=server_url,
|
|
||||||
params=params,
|
|
||||||
timeout=timeout,
|
|
||||||
super_component_expansion=super_component_expansion,
|
|
||||||
)
|
|
||||||
|
|
||||||
def _draw_internal(
|
|
||||||
self,
|
|
||||||
*,
|
|
||||||
path: Path,
|
|
||||||
server_url: str = "https://mermaid.ink",
|
|
||||||
params: Optional[dict] = None,
|
|
||||||
timeout: int = 30,
|
|
||||||
super_component_expansion: bool = False,
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Internal implementation of draw() that uses keyword-only arguments.
|
|
||||||
|
|
||||||
ToDo: after 2.14.0 release make this the main function and remove the old one.
|
|
||||||
"""
|
|
||||||
# Before drawing we edit a bit the graph, to avoid modifying the original that is
|
# Before drawing we edit a bit the graph, to avoid modifying the original that is
|
||||||
# used for running the pipeline we copy it.
|
# used for running the pipeline we copy it.
|
||||||
if super_component_expansion:
|
if super_component_expansion:
|
||||||
|
|||||||
@ -183,7 +183,6 @@ def args_deprecated(func):
|
|||||||
msg = (
|
msg = (
|
||||||
"Warning: In an upcoming release, this method will require keyword arguments for all parameters. "
|
"Warning: In an upcoming release, this method will require keyword arguments for all parameters. "
|
||||||
"Please update your code to use keyword arguments to ensure future compatibility. "
|
"Please update your code to use keyword arguments to ensure future compatibility. "
|
||||||
"Example: pipeline.draw(path='output.png', server_url='https://custom-server.com')"
|
|
||||||
)
|
)
|
||||||
warnings.warn(msg, DeprecationWarning, stacklevel=2)
|
warnings.warn(msg, DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
upgrade:
|
||||||
|
- |
|
||||||
|
All parameters of the Pipeline.draw() and Pipeline.show() methods must now be specified as keyword arguments
|
||||||
|
Example:
|
||||||
|
pipeline.draw(
|
||||||
|
path="output.png",
|
||||||
|
server_url="https://custom-server.com",
|
||||||
|
params=None,
|
||||||
|
timeout=30,
|
||||||
|
super_component_expansion=False
|
||||||
|
)
|
||||||
@ -1677,87 +1677,6 @@ class TestPipelineBase:
|
|||||||
|
|
||||||
assert consumed["input1"].equals(DataFrame({"a": [1, 2], "b": [1, 2]}))
|
assert consumed["input1"].equals(DataFrame({"a": [1, 2], "b": [1, 2]}))
|
||||||
|
|
||||||
@patch("haystack.core.pipeline.draw.requests")
|
|
||||||
def test_pipeline_draw_called_with_positional_args_triggers_a_warning(self, mock_requests, tmp_path):
|
|
||||||
"""
|
|
||||||
Test that calling the pipeline draw method with positional arguments raises a warning.
|
|
||||||
"""
|
|
||||||
import warnings
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
pipeline = PipelineBase()
|
|
||||||
mock_response = mock_requests.get.return_value
|
|
||||||
mock_response.status_code = 200
|
|
||||||
mock_response.content = b"image_data"
|
|
||||||
out_file = tmp_path / "original_pipeline.png"
|
|
||||||
with warnings.catch_warnings(record=True) as w:
|
|
||||||
pipeline.draw(out_file, server_url="http://localhost:3000")
|
|
||||||
assert len(w) == 1
|
|
||||||
assert issubclass(w[0].category, DeprecationWarning)
|
|
||||||
assert (
|
|
||||||
"Warning: In an upcoming release, this method will require keyword arguments for all parameters"
|
|
||||||
in str(w[0].message)
|
|
||||||
)
|
|
||||||
|
|
||||||
@patch("haystack.core.pipeline.draw.requests")
|
|
||||||
@patch("haystack.core.pipeline.base.is_in_jupyter")
|
|
||||||
def test_pipeline_show_called_with_positional_args_triggers_a_warning(self, mock_is_in_jupyter, mock_requests):
|
|
||||||
"""
|
|
||||||
Test that calling the pipeline show method with positional arguments raises a warning.
|
|
||||||
"""
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
pipeline = PipelineBase()
|
|
||||||
mock_response = mock_requests.get.return_value
|
|
||||||
mock_response.status_code = 200
|
|
||||||
mock_response.content = b"image_data"
|
|
||||||
mock_is_in_jupyter.return_value = True
|
|
||||||
|
|
||||||
with warnings.catch_warnings(record=True) as w:
|
|
||||||
pipeline.show("http://localhost:3000")
|
|
||||||
assert len(w) == 1
|
|
||||||
assert issubclass(w[0].category, DeprecationWarning)
|
|
||||||
assert (
|
|
||||||
"Warning: In an upcoming release, this method will require keyword arguments for all parameters"
|
|
||||||
in str(w[0].message)
|
|
||||||
)
|
|
||||||
|
|
||||||
@patch("haystack.core.pipeline.draw.requests")
|
|
||||||
def test_pipeline_draw_called_with_keyword_args_triggers_no_warning(self, mock_requests, tmp_path):
|
|
||||||
"""
|
|
||||||
Test that calling the pipeline draw method with keyword arguments does not raise a warning.
|
|
||||||
"""
|
|
||||||
import warnings
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
pipeline = PipelineBase()
|
|
||||||
mock_response = mock_requests.get.return_value
|
|
||||||
mock_response.status_code = 200
|
|
||||||
mock_response.content = b"image_data"
|
|
||||||
out_file = tmp_path / "original_pipeline.png"
|
|
||||||
|
|
||||||
with warnings.catch_warnings(record=True) as w:
|
|
||||||
pipeline.draw(path=out_file, server_url="http://localhost:3000")
|
|
||||||
assert len(w) == 0, "No warning should be triggered when using keyword arguments"
|
|
||||||
|
|
||||||
@patch("haystack.core.pipeline.draw.requests")
|
|
||||||
@patch("haystack.core.pipeline.base.is_in_jupyter")
|
|
||||||
def test_pipeline_show_called_with_keyword_args_triggers_no_warning(self, mock_is_in_jupyter, mock_requests):
|
|
||||||
"""
|
|
||||||
Test that calling the pipeline show method with keyword arguments does not raise a warning.
|
|
||||||
"""
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
pipeline = PipelineBase()
|
|
||||||
mock_response = mock_requests.get.return_value
|
|
||||||
mock_response.status_code = 200
|
|
||||||
mock_response.content = b"image_data"
|
|
||||||
mock_is_in_jupyter.return_value = True
|
|
||||||
|
|
||||||
with warnings.catch_warnings(record=True) as w:
|
|
||||||
pipeline.show(server_url="http://localhost:3000")
|
|
||||||
assert len(w) == 0, "No warning should be triggered when using keyword arguments"
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_find_super_components(self):
|
def test_find_super_components(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user