Example #1
0
    def test_2d(self, order):
        dti = pd.date_range("2016-01-01", periods=6, tz="US/Pacific")
        arr = np.array(dti, dtype=object).reshape(3, 2)
        if order == "F":
            arr = arr.T

        res = _sequence_to_dt64ns(arr)
        expected = _sequence_to_dt64ns(arr.ravel())

        tm.assert_numpy_array_equal(res[0].ravel(), expected[0])
        assert res[1] == expected[1]
        assert res[2] == expected[2]

        res = DatetimeArray._from_sequence(arr)
        expected = DatetimeArray._from_sequence(arr.ravel()).reshape(arr.shape)
        tm.assert_datetime_array_equal(res, expected)
Example #2
0
    def test_bool_dtype_raises(self):
        arr = np.array([1, 2, 3], dtype="bool")

        msg = "Unexpected value for 'dtype': 'bool'. Must be"
        with pytest.raises(ValueError, match=msg):
            DatetimeArray(arr)

        msg = r"dtype bool cannot be converted to datetime64\[ns\]"
        with pytest.raises(TypeError, match=msg):
            DatetimeArray._from_sequence(arr)

        with pytest.raises(TypeError, match=msg):
            _sequence_to_dt64ns(arr)

        with pytest.raises(TypeError, match=msg):
            pd.DatetimeIndex(arr)

        with pytest.raises(TypeError, match=msg):
            pd.to_datetime(arr)
Example #3
0
    def test_bool_dtype_raises(self):
        arr = np.array([1, 2, 3], dtype="bool")

        with pytest.raises(ValueError,
                           match="The dtype of 'values' is incorrect.*bool"):
            DatetimeArray(arr)

        msg = r"dtype bool cannot be converted to datetime64\[ns\]"
        with pytest.raises(TypeError, match=msg):
            DatetimeArray._from_sequence(arr)

        with pytest.raises(TypeError, match=msg):
            _sequence_to_dt64ns(arr)

        with pytest.raises(TypeError, match=msg):
            pd.DatetimeIndex(arr)

        with pytest.raises(TypeError, match=msg):
            pd.to_datetime(arr)
Example #4
0
 def test_tz_dtype_matches(self):
     arr = DatetimeArray._from_sequence(
         ["2000"], dtype=DatetimeTZDtype(tz="US/Central")
     )
     result, _, _ = _sequence_to_dt64ns(arr, dtype=DatetimeTZDtype(tz="US/Central"))
     tm.assert_numpy_array_equal(arr._data, result)
Example #5
0
 def test_tz_dtype_mismatch_raises(self):
     arr = DatetimeArray._from_sequence(
         ["2000"], dtype=DatetimeTZDtype(tz="US/Central")
     )
     with pytest.raises(TypeError, match="data is already tz-aware"):
         _sequence_to_dt64ns(arr, dtype=DatetimeTZDtype(tz="UTC"))