Repository: activeloopai/Hub
File: deeplake/auto/structured/dataframe.py (Python)

Code before:
            else:
                tensor_params.update(
                    dtype=dtype,
                    create_shape_tensor=tensor_params.get("create_shape_tensor", False),
                )  # htype will be auto-inferred for numeric data unless the htype is specified in tensor_params

        # TODO: Make this more robust so it works for all htypes where sample_compression is required and should be inferred from the data itself
        if (
            "image" in tensor_params.get("htype", "")
            and "sample_compression" not in tensor_params.keys()
            and "chunk_compression" not in tensor_params.keys()
        ):
            tensor_params.update(
                sample_compression=self._get_most_frequent_image_extension(
                    self.source[key].values
                )
            )

        return tensor_params

    def _get_extend_values(self, tensor_params: dict, key: str):  # type: ignore
        """Method creates a list of values to be extended to the tensor, based on the tensor parameters and the data in the dataframe column"""

        extend_values: List[Optional[Union[Sample, LinkedSample, np.ndarray]]]

        if "htype" in tensor_params.keys() and "link[" in tensor_params["htype"]:
            extend_values = [
                link(value, creds_key=self.creds_key) if value is not None else None
                for value in self.source[key].values
            ]
        elif "htype" in tensor_params.keys() and "image" in tensor_params["htype"]:
            extend_values = [
                read(value, creds=self.creds) if value is not None else None
                for value in self.source[key].values
            ]
        else:
            extend_values = self.source[key].values

        return extend_values

    def fill_dataset(self, ds: Dataset, progressbar: bool = True) -> Dataset:
        """Fill dataset with data from the dataframe - one tensor per column

        Args:
            ds (Dataset) : A Deep Lake dataset object.
            progressbar (bool) : Defines if the method uses a progress bar. Defaults to True.

        Returns:
            A Deep Lake dataset.

        """

Review comment (suggestion):
```suggestion
        if "htype" in tensor_params and "link[" in tensor_params["htype"]:
```

Code after:
        elif "htype" in tensor_params and "image" in tensor_params["htype"]:
            extend_values = [
                read(value, creds=self.creds) if value is not None else None
                for value in self.source[key].values
            ]
        else:
            extend_values = self.source[key].values

        return extend_values

    def fill_dataset(self, ds: Dataset, progressbar: bool = True) -> Dataset:
        """Fill dataset with data from the dataframe - one tensor per column

        Args:
            ds (Dataset) : A Deep Lake dataset object.
            progressbar (bool) : Defines if the method uses a progress bar. Defaults to True.

        Returns:
            A Deep Lake dataset.

        """

        keys = list(self.source.columns)

        with ds:
            if self.creds_key is not None and self.creds_key not in ds.get_creds_keys():
                ds.add_creds_key(self.creds_key, managed=True)
            for key in keys:
                if progressbar:
                    logger.info(f"Ingesting column '{key}'")

                tensor_params = self._parse_tensor_params(key)

                if tensor_params["name"] not in ds.tensors:
                    ds.create_tensor(**tensor_params)

                ds[tensor_params["name"]].extend(
                    self._get_extend_values(tensor_params, key),
                    progressbar=progressbar,
                )
        return ds