示例#1
0
    def test_construction_from_string_error_subtype(self, string):
        # this is an invalid subtype
        msg = ("Incorrectly formatted string passed to constructor. "
               r"Valid formats include Interval or Interval\[dtype\] "
               "where dtype is numeric, datetime, or timedelta")

        with pytest.raises(TypeError, match=msg):
            IntervalDtype.construct_from_string(string)
示例#2
0
    def test_construction_from_string_errors(self, string):
        if isinstance(string, string_types):
            error, msg = ValueError, 'could not construct IntervalDtype'
        else:
            error, msg = TypeError, 'a string needs to be passed, got type'

        with tm.assert_raises_regex(error, msg):
            IntervalDtype.construct_from_string(string)
示例#3
0
    def test_construction_from_string_error_subtype(self, string):
        # this is an invalid subtype
        msg = ("Incorrectly formatted string passed to constructor. "
               r"Valid formats include Interval or Interval\[dtype\] "
               "where dtype is numeric, datetime, or timedelta")

        with pytest.raises(TypeError, match=msg):
            IntervalDtype.construct_from_string(string)
示例#4
0
    def test_construction_from_string_errors(self, string):
        if isinstance(string, string_types):
            error, msg = ValueError, 'could not construct IntervalDtype'
        else:
            error, msg = TypeError, 'a string needs to be passed, got type'

        with tm.assert_raises_regex(error, msg):
            IntervalDtype.construct_from_string(string)
示例#5
0
 def test_construction_from_string(self):
     result = IntervalDtype('interval[int64]')
     self.assertTrue(is_dtype_equal(self.dtype, result))
     result = IntervalDtype.construct_from_string('interval[int64]')
     self.assertTrue(is_dtype_equal(self.dtype, result))
     with pytest.raises(TypeError):
         IntervalDtype.construct_from_string('foo')
     with pytest.raises(TypeError):
         IntervalDtype.construct_from_string('interval[foo]')
     with pytest.raises(TypeError):
         IntervalDtype.construct_from_string('foo[int64]')
示例#6
0
 def test_construction_from_string(self):
     result = IntervalDtype('interval[int64]')
     self.assertTrue(is_dtype_equal(self.dtype, result))
     result = IntervalDtype.construct_from_string('interval[int64]')
     self.assertTrue(is_dtype_equal(self.dtype, result))
     with tm.assertRaises(TypeError):
         IntervalDtype.construct_from_string('foo')
     with tm.assertRaises(TypeError):
         IntervalDtype.construct_from_string('interval[foo]')
     with tm.assertRaises(TypeError):
         IntervalDtype.construct_from_string('foo[int64]')
示例#7
0
 def test_construction_from_string(self):
     result = IntervalDtype('interval[int64]')
     assert is_dtype_equal(self.dtype, result)
     result = IntervalDtype.construct_from_string('interval[int64]')
     assert is_dtype_equal(self.dtype, result)
     with pytest.raises(TypeError):
         IntervalDtype.construct_from_string('foo')
     with pytest.raises(TypeError):
         IntervalDtype.construct_from_string('interval[foo]')
     with pytest.raises(TypeError):
         IntervalDtype.construct_from_string('foo[int64]')
示例#8
0
    def test_construction_from_string_errors(self, string):
        # these are invalid entirely
        msg = "a string needs to be passed, got type"

        with pytest.raises(TypeError, match=msg):
            IntervalDtype.construct_from_string(string)
示例#9
0
    def test_construction_from_string_error_subtype(self, string):
        # this is an invalid subtype
        msg = 'could not construct IntervalDtype'

        with pytest.raises(TypeError, match=msg):
            IntervalDtype.construct_from_string(string)
示例#10
0
 def test_construction_from_string(self):
     result = IntervalDtype('interval[int64]')
     assert is_dtype_equal(self.dtype, result)
     result = IntervalDtype.construct_from_string('interval[int64]')
     assert is_dtype_equal(self.dtype, result)
示例#11
0
    def test_construction_from_string_errors(self, string):
        # these are invalid entirely
        msg = 'a string needs to be passed, got type'

        with tm.assert_raises_regex(TypeError, msg):
            IntervalDtype.construct_from_string(string)
示例#12
0
 def test_construction_from_string(self, dtype):
     result = IntervalDtype("interval[int64]")
     assert is_dtype_equal(dtype, result)
     result = IntervalDtype.construct_from_string("interval[int64]")
     assert is_dtype_equal(dtype, result)
示例#13
0
    def test_construction_from_string_error_subtype(self, string):
        # this is an invalid subtype
        msg = 'could not construct IntervalDtype'

        with tm.assert_raises_regex(TypeError, msg):
            IntervalDtype.construct_from_string(string)
示例#14
0
    def test_construction_from_string_errors(self, string):
        # these are invalid entirely
        msg = 'a string needs to be passed, got type'

        with tm.assert_raises_regex(TypeError, msg):
            IntervalDtype.construct_from_string(string)
示例#15
0
 def dtype(self):
     """Return the dtype object of the underlying data"""
     return IntervalDtype.construct_from_string(str(self.left.dtype))
示例#16
0
 def test_construction_from_string(self):
     result = IntervalDtype('interval[int64]')
     assert is_dtype_equal(self.dtype, result)
     result = IntervalDtype.construct_from_string('interval[int64]')
     assert is_dtype_equal(self.dtype, result)
示例#17
0
    def test_construction_from_string_errors(self, string):
        # these are invalid entirely
        msg = f"'construct_from_string' expects a string, got {type(string)}"

        with pytest.raises(TypeError, match=re.escape(msg)):
            IntervalDtype.construct_from_string(string)
示例#18
0
 def dtype(self):
     return IntervalDtype.construct_from_string(str(self.left.dtype))
示例#19
0
    def test_construction_from_string_errors(self, string):
        # these are invalid entirely
        msg = 'a string needs to be passed, got type'

        with pytest.raises(TypeError, match=msg):
            IntervalDtype.construct_from_string(string)
示例#20
0
    def test_construction_from_string_error_subtype(self, string):
        # this is an invalid subtype
        msg = 'could not construct IntervalDtype'

        with tm.assert_raises_regex(TypeError, msg):
            IntervalDtype.construct_from_string(string)
示例#21
0
    def test_construction_from_string_error_subtype(self, string):
        # this is an invalid subtype
        msg = 'could not construct IntervalDtype'

        with pytest.raises(TypeError, match=msg):
            IntervalDtype.construct_from_string(string)
示例#22
0
文件: interval.py 项目: qdxt/python
 def dtype(self):
     return IntervalDtype.construct_from_string(str(self.left.dtype))
示例#23
0
文件: interval.py 项目: mficek/pandas
 def dtype(self):
     """Return the dtype object of the underlying data"""
     return IntervalDtype.construct_from_string(str(self.left.dtype))