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

Code before:

        if new_data.dtype == "object":
            try:
                new_data = data.astype("int64")
            except OverflowError:
                return data
            except (TypeError, ValueError):
                pass

        # ignore numbers that are out of range
        if issubclass(new_data.dtype.type, np.number):
            in_range = (
                isna(new_data._values)
                | (new_data > self.min_stamp)
                | (new_data._values == iNaT)
            )
            if not in_range.all():
                return data

        date_units = (self.date_unit,) if self.date_unit else self._STAMP_UNITS
        for date_unit in date_units:
            try:
                # Without this as_unit cast, we would fail to overflow
                #  and get much-too-large dates
                return to_datetime(new_data, errors="raise", unit=date_unit).dt.as_unit(
                    "ns"
                )
            except (ValueError, OverflowError, TypeError):
                continue
        return data


class SeriesParser(Parser):
    _default_orient = "index"
    _split_keys = ("name", "index", "data")

    def _parse(self) -> Series:
        data = ujson_loads(self.json, precise_float=self.precise_float)

        if self.orient == "split":
            decoded = {str(k): v for k, v in data.items()}
            self.check_keys_split(decoded)
            return Series(**decoded)
        else:
            return Series(data)

    def _try_convert_types(self, obj: Series) -> Series:
        obj, _ = self._try_convert_data("data", obj, convert_dates=self.convert_dates)
        return obj



Review comment (bug):
I am not directly understanding that comment. `new_data` are integers here? Why does the return unit of this function need to be nanoseconds? (to preserve current functionality?) Why would this give (wrong?) too large dates? 

Code after:

        if new_data.dtype == "object":
            try:
                new_data = data.astype("int64")
            except OverflowError:
                return data
            except (TypeError, ValueError):
                pass

        # ignore numbers that are out of range
        if issubclass(new_data.dtype.type, np.number):
            in_range = (
                isna(new_data._values)
                | (new_data > self.min_stamp)
                | (new_data._values == iNaT)
            )
            if not in_range.all():
                return data

        date_units = (self.date_unit,) if self.date_unit else self._STAMP_UNITS
        for date_unit in date_units:
            try:
                # In case of multiple possible units, infer the likely unit
                # based on the first unit for which the parsed dates fit
                # within the nanoseconds bounds
                # -> do as_unit cast to ensure OutOfBounds error
                return to_datetime(new_data, errors="raise", unit=date_unit).dt.as_unit(
                    "ns"
                )
            except (ValueError, OverflowError, TypeError):
                continue
        return data


class SeriesParser(Parser):
    _default_orient = "index"
    _split_keys = ("name", "index", "data")

    def _parse(self) -> Series:
        data = ujson_loads(self.json, precise_float=self.precise_float)

        if self.orient == "split":
            decoded = {str(k): v for k, v in data.items()}
            self.check_keys_split(decoded)
            return Series(**decoded)
        else:
            return Series(data)

    def _try_convert_types(self, obj: Series) -> Series:
        obj, _ = self._try_convert_data("data", obj, convert_dates=self.convert_dates)
        return obj