Esempio n. 1
0
 def time_tz_convert_from_utc(self, size, tz):
     # effectively:
     #  dti = DatetimeIndex(self.i8data, tz=tz)
     #  dti.tz_localize(None)
     if old_sig:
         tz_convert_from_utc(self.i8data, UTC, tz)
     else:
         tz_convert_from_utc(self.i8data, tz)
Esempio n. 2
0
def test_tz_localize_to_utc_copies():
    # GH#46460
    arr = np.arange(5, dtype="i8")
    result = tz_convert_from_utc(arr, tz=UTC)
    tm.assert_numpy_array_equal(result, arr)
    assert not np.shares_memory(arr, result)

    result = tz_convert_from_utc(arr, tz=None)
    tm.assert_numpy_array_equal(result, arr)
    assert not np.shares_memory(arr, result)
Esempio n. 3
0
def _compare_utc_to_local(tz_didx):
    def f(x):
        return tzconversion.tz_convert_from_utc_single(x, tz_didx.tz)

    result = tz_convert_from_utc(tz_didx.asi8, tz_didx.tz)
    expected = np.vectorize(f)(tz_didx.asi8)

    tm.assert_numpy_array_equal(result, expected)
Esempio n. 4
0
    def __init__(self, index, warn: bool = True) -> None:
        self.index = index
        self.i8values = index.asi8

        # For get_unit_from_dtype we need the dtype to the underlying ndarray,
        #  which for tz-aware is not the same as index.dtype
        if isinstance(index, ABCIndex):
            # error: Item "ndarray[Any, Any]" of "Union[ExtensionArray,
            # ndarray[Any, Any]]" has no attribute "_ndarray"
            self._reso = get_unit_from_dtype(
                index._data._ndarray.dtype  # type: ignore[union-attr]
            )
        else:
            # otherwise we have DTA/TDA
            self._reso = get_unit_from_dtype(index._ndarray.dtype)

        # This moves the values, which are implicitly in UTC, to the
        # the timezone so they are in local time
        if hasattr(index, "tz"):
            if index.tz is not None:
                self.i8values = tz_convert_from_utc(self.i8values, index.tz)

        if warn is not True:
            warnings.warn(
                "warn is deprecated (and never implemented) and "
                "will be removed in a future version.",
                FutureWarning,
                stacklevel=3,
            )
        self.warn = warn

        if len(index) < 3:
            raise ValueError("Need at least 3 dates to infer frequency")

        self.is_monotonic = (
            self.index._is_monotonic_increasing or self.index._is_monotonic_decreasing
        )
Esempio n. 5
0
    def __init__(self, index, warn: bool = True) -> None:
        self.index = index
        self.i8values = index.asi8

        # This moves the values, which are implicitly in UTC, to the
        # the timezone so they are in local time
        if hasattr(index, "tz"):
            if index.tz is not None:
                self.i8values = tz_convert_from_utc(self.i8values, index.tz)

        if warn is not True:
            warnings.warn(
                "warn is deprecated (and never implemented) and "
                "will be removed in a future version.",
                FutureWarning,
                stacklevel=3,
            )
        self.warn = warn

        if len(index) < 3:
            raise ValueError("Need at least 3 dates to infer frequency")

        self.is_monotonic = (self.index._is_monotonic_increasing
                             or self.index._is_monotonic_decreasing)
Esempio n. 6
0
def test_tz_convert_readonly():
    # GH#35530
    arr = np.array([0], dtype=np.int64)
    arr.setflags(write=False)
    result = tz_convert_from_utc(arr, UTC)
    tm.assert_numpy_array_equal(result, arr)
Esempio n. 7
0
def test_tz_convert_corner(arr):
    result = tz_convert_from_utc(arr, timezones.maybe_get_tz("Asia/Tokyo"))
    tm.assert_numpy_array_equal(result, arr)