Example #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])
Example #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]')
Example #3
0
 def dtype(self):
     return PeriodDtype.construct_from_string(self.freq)
Example #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]')
Example #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])
Example #6
0
 def dtype(self):
     return PeriodDtype.construct_from_string(self.freq)
Example #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)