thod instead, we would not need to make this copy.It is worth noting that copying the artifact to a local path may not always be necessary and can potentially be a performance bottleneck.

import os

from typing import Any, ClassVar, Dict, Optional, Tuple, Type, Union

import pandas as pd

from zenml.artifact_stores.base_artifact_store import BaseArtifactStore

from zenml.enums import ArtifactType, VisualizationType

from zenml.logger import get_logger

from zenml.materializers.base_materializer import BaseMaterializer

from zenml.metadata.metadata_types import DType, MetadataType

logger = get_logger(__name__)

PARQUET_FILENAME = "df.parquet.gzip"

COMPRESSION_TYPE = "gzip"

CSV_FILENAME = "df.csv"

class PandasMaterializer(BaseMaterializer):

"""Materializer to read data to and from pandas."""

ASSOCIATED_TYPES: ClassVar[Tuple[Type[Any], ...]] = (

pd.DataFrame,

pd.Series,

ASSOCIATED_ARTIFACT_TYPE: ClassVar[ArtifactType] = ArtifactType.DATA

def __init__(

self, uri: str, artifact_store: Optional[BaseArtifactStore] = None

):

"""Define `self.data_path`.

Args:

uri: The URI where the artifact data is stored.

artifact_store: The artifact store where the artifact data is stored.

"""

super().__init__(uri, artifact_store)

try:

import pyarrow  # type: ignore # noqa

self.pyarrow_exists = True

except ImportError:

self.pyarrow_exists = False

logger.warning(

"By default, the `PandasMaterializer` stores data as a "

"`.csv` file. If you want to store data more efficiently, "

"you can install `pyarrow` by running "

"'`pip install pyarrow`'. This will allow `PandasMaterializer` "

"to automatically store the data as a `.parquet` file instead."

finally:

self.parquet_path = os.path.join(self.uri, PARQUET_FILENAME)

self.csv_path = os.path.join(self.uri, CSV_FILENAME)

def load(self, data_type: Type[Any]) -> Union[pd.DataFrame, pd.Series]:

"""Reads `pd.DataFrame` or `pd.Series` from a `.parquet` or `.csv` file.

Args:

data_type: The type of the data to read.

Raises: