Esempio n. 1
0
    def test_construction_from_string(self, dtype):
        result = PeriodDtype("period[D]")
        assert is_dtype_equal(dtype, result)
        result = PeriodDtype.construct_from_string("period[D]")
        assert is_dtype_equal(dtype, result)

        with pytest.raises(TypeError, match="list"):
            PeriodDtype.construct_from_string([1, 2, 3])
Esempio n. 2
0
    def test_construction_from_string(self):
        result = PeriodDtype('period[D]')
        assert is_dtype_equal(self.dtype, result)
        result = PeriodDtype.construct_from_string('period[D]')
        assert is_dtype_equal(self.dtype, result)
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string('foo')
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string('period[foo]')
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string('foo[D]')

        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string('datetime64[ns]')
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string('datetime64[ns, US/Eastern]')
Esempio n. 3
0
 def dtype(self):
     return PeriodDtype.construct_from_string(self.freq)
Esempio n. 4
0
    def test_construction_from_string(self):
        result = PeriodDtype('period[D]')
        assert is_dtype_equal(self.dtype, result)
        result = PeriodDtype.construct_from_string('period[D]')
        assert is_dtype_equal(self.dtype, result)
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string('foo')
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string('period[foo]')
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string('foo[D]')

        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string('datetime64[ns]')
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string('datetime64[ns, US/Eastern]')
Esempio n. 5
0
    def test_construction_from_string(self):
        result = PeriodDtype("period[D]")
        assert is_dtype_equal(self.dtype, result)
        result = PeriodDtype.construct_from_string("period[D]")
        assert is_dtype_equal(self.dtype, result)
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string("foo")
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string("period[foo]")
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string("foo[D]")

        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string("datetime64[ns]")
        with pytest.raises(TypeError):
            PeriodDtype.construct_from_string("datetime64[ns, US/Eastern]")

        with pytest.raises(TypeError, match="list"):
            PeriodDtype.construct_from_string([1, 2, 3])
Esempio n. 6
0
 def dtype(self):
     return PeriodDtype.construct_from_string(self.freq)
Esempio n. 7
0
 def test_construct_dtype_from_string_invalid_raises(self, string):
     msg = f"Cannot construct a 'PeriodDtype' from '{string}'"
     with pytest.raises(TypeError, match=re.escape(msg)):
         PeriodDtype.construct_from_string(string)