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

Code before:

        if new_data.dtype == "string":
            new_data = new_data.astype(object)

        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)

Review comment (suggestion):
something like this:

```suggestion
                # 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 
```

Code after:

        if new_data.dtype == "string":
            new_data = new_data.astype(object)

        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)