23
23
24
24
class Base (object ):
25
25
26
+ def setUp (self ):
27
+ self .dtype = self .create ()
28
+
26
29
def test_hash (self ):
27
30
hash (self .dtype )
28
31
@@ -37,14 +40,38 @@ def test_numpy_informed(self):
37
40
assert not np .str_ == self .dtype
38
41
39
42
def test_pickle (self ):
43
+ # make sure our cache is NOT pickled
44
+
45
+ # clear the cache
46
+ type (self .dtype ).reset_cache ()
47
+ assert not len (self .dtype ._cache )
48
+
49
+ # force back to the cache
40
50
result = tm .round_trip_pickle (self .dtype )
51
+ assert not len (self .dtype ._cache )
41
52
assert result == self .dtype
42
53
43
54
44
55
class TestCategoricalDtype (Base , tm .TestCase ):
45
56
46
- def setUp (self ):
47
- self .dtype = CategoricalDtype ()
57
+ def create (self ):
58
+ return CategoricalDtype ()
59
+
60
+ def test_pickle (self ):
61
+ # make sure our cache is NOT pickled
62
+
63
+ # clear the cache
64
+ type (self .dtype ).reset_cache ()
65
+ assert not len (self .dtype ._cache )
66
+
67
+ # force back to the cache
68
+ result = tm .round_trip_pickle (self .dtype )
69
+
70
+ # we are a singular object so we are added
71
+ # back to the cache upon unpickling
72
+ # this is to ensure object identity
73
+ assert len (self .dtype ._cache ) == 1
74
+ assert result == self .dtype
48
75
49
76
def test_hash_vs_equality (self ):
50
77
# make sure that we satisfy is semantics
@@ -95,8 +122,8 @@ def test_basic(self):
95
122
96
123
class TestDatetimeTZDtype (Base , tm .TestCase ):
97
124
98
- def setUp (self ):
99
- self . dtype = DatetimeTZDtype ('ns' , 'US/Eastern' )
125
+ def create (self ):
126
+ return DatetimeTZDtype ('ns' , 'US/Eastern' )
100
127
101
128
def test_hash_vs_equality (self ):
102
129
# make sure that we satisfy is semantics
@@ -211,8 +238,8 @@ def test_empty(self):
211
238
212
239
class TestPeriodDtype (Base , tm .TestCase ):
213
240
214
- def setUp (self ):
215
- self . dtype = PeriodDtype ('D' )
241
+ def create (self ):
242
+ return PeriodDtype ('D' )
216
243
217
244
def test_construction (self ):
218
245
with pytest .raises (ValueError ):
@@ -340,9 +367,22 @@ def test_not_string(self):
340
367
341
368
class TestIntervalDtype (Base , tm .TestCase ):
342
369
343
- # TODO: placeholder
344
- def setUp (self ):
345
- self .dtype = IntervalDtype ('int64' )
370
+ def create (self ):
371
+ return IntervalDtype ('int64' )
372
+
373
+ def test_hash_vs_equality (self ):
374
+ # make sure that we satisfy is semantics
375
+ dtype = self .dtype
376
+ dtype2 = IntervalDtype ('int64' )
377
+ dtype3 = IntervalDtype (dtype2 )
378
+ assert dtype == dtype2
379
+ assert dtype2 == dtype
380
+ assert dtype3 == dtype
381
+ assert dtype is dtype2
382
+ assert dtype2 is dtype
383
+ assert dtype3 is dtype
384
+ assert hash (dtype ) == hash (dtype2 )
385
+ assert hash (dtype ) == hash (dtype3 )
346
386
347
387
def test_construction (self ):
348
388
with pytest .raises (ValueError ):
@@ -445,3 +485,14 @@ def test_basic_dtype(self):
445
485
assert not is_interval_dtype (np .object_ )
446
486
assert not is_interval_dtype (np .int64 )
447
487
assert not is_interval_dtype (np .float64 )
488
+
489
+ def test_caching (self ):
490
+ IntervalDtype .reset_cache ()
491
+ dtype = IntervalDtype ("int64" )
492
+ assert len (IntervalDtype ._cache ) == 1
493
+
494
+ IntervalDtype ("interval" )
495
+ assert len (IntervalDtype ._cache ) == 1
496
+
497
+ tm .round_trip_pickle (dtype )
498
+ assert len (IntervalDtype ._cache ) == 1
0 commit comments