Repository: pandas-dev/pandas
File: pandas/io/pytables.py (Python)

Code before:

        # values is a recarray
        if values.dtype.fields is not None:
            values = values[self.cname]

        assert self.typ is not None
        if self.dtype is None:
            # Note: in tests we never have timedelta64 or datetime64,
            #  so the _get_data_and_dtype_name may be unnecessary
            converted, dtype_name = _get_data_and_dtype_name(values)
            kind = _dtype_to_kind(dtype_name)
        else:
            converted = values
            dtype_name = self.dtype
            kind = self.kind

        assert isinstance(converted, np.ndarray)  # for mypy

        # use the meta if needed
        meta = self.meta
        metadata = self.metadata
        ordered = self.ordered
        tz = self.tz

        assert dtype_name is not None
        dtype = dtype_name

        if dtype.startswith("datetime64"):
            # Handle legacy files without unit specifier (GH#64006)
            if dtype == "datetime64":
                dtype = "datetime64[ns]"
            converted = _set_tz(converted, tz, dtype)

        elif dtype.startswith("timedelta64"):
            if dtype == "timedelta64":
                converted = np.asarray(converted, dtype="m8[ns]")
            else:
                converted = np.asarray(converted, dtype=dtype)
        elif dtype == "date":
            try:
                converted = np.asarray(
                    [date.fromordinal(v) for v in converted], dtype=object
                )
            except ValueError:
                converted = np.asarray(
                    [date.fromtimestamp(v) for v in converted], dtype=object
                )

        elif meta == "category":
            # we have a categorical
            categories = metadata

Review comment (suggestion):
Can you leave all current comments as they are (unless your actual code change would make them no longer correct)

I don't know if the comment on the line here is very useful, but at least below there are several useful comments that you are deleting. In general best to not make unrelated changes to keep the diff as small as possible

Code after:

        # values is a recarray
        if values.dtype.fields is not None:
            values = values[self.cname]

        assert self.typ is not None
        if self.dtype is None:
            # Note: in tests we never have timedelta64 or datetime64,
            #  so the _get_data_and_dtype_name may be unnecessary
            converted, dtype_name = _get_data_and_dtype_name(values)
            kind = _dtype_to_kind(dtype_name)
        else:
            converted = values
            dtype_name = self.dtype
            kind = self.kind

        assert isinstance(converted, np.ndarray)  # for mypy

        # use the meta if needed
        meta = self.meta
        metadata = self.metadata
        ordered = self.ordered
        tz = self.tz

        assert dtype_name is not None
        # convert to the correct dtype
        dtype = dtype_name

        # reverse converts
        if dtype.startswith("datetime64"):
            # recreate with tz if indicated
            if dtype == "datetime64":
                dtype = "datetime64[ns]"
            converted = _set_tz(converted, tz, dtype)

        elif dtype.startswith("timedelta64"):
            if dtype == "timedelta64":
                # from before we started storing timedelta64 unit
                converted = np.asarray(converted, dtype="m8[ns]")
            else:
                converted = np.asarray(converted, dtype=dtype)
        elif dtype == "date":
            try:
                converted = np.asarray(
                    [date.fromordinal(v) for v in converted], dtype=object
                )
            except ValueError:
                converted = np.asarray(
                    [date.fromtimestamp(v) for v in converted], dtype=object
                )