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