@@ -79,74 +79,14 @@ def data_for_grouping():
7979
8080
8181class BaseJSON :
82- # NumPy doesn't handle an array of equal-length UserDicts.
83- # The default assert_series_equal eventually does a
84- # Series.values, which raises. We work around it by
85- # converting the UserDicts to dicts.
86- @classmethod
87- def assert_series_equal (cls , left , right , * args , ** kwargs ):
88- if left .dtype .name == "json" :
89- assert left .dtype == right .dtype
90- left = pd .Series (
91- JSONArray (left .values .astype (object )), index = left .index , name = left .name
92- )
93- right = pd .Series (
94- JSONArray (right .values .astype (object )),
95- index = right .index ,
96- name = right .name ,
97- )
98- tm .assert_series_equal (left , right , * args , ** kwargs )
99-
100- @classmethod
101- def assert_frame_equal (cls , left , right , * args , ** kwargs ):
102- obj_type = kwargs .get ("obj" , "DataFrame" )
103- tm .assert_index_equal (
104- left .columns ,
105- right .columns ,
106- exact = kwargs .get ("check_column_type" , "equiv" ),
107- check_names = kwargs .get ("check_names" , True ),
108- check_exact = kwargs .get ("check_exact" , False ),
109- check_categorical = kwargs .get ("check_categorical" , True ),
110- obj = f"{ obj_type } .columns" ,
111- )
112-
113- jsons = (left .dtypes == "json" ).index
114-
115- for col in jsons :
116- cls .assert_series_equal (left [col ], right [col ], * args , ** kwargs )
117-
118- left = left .drop (columns = jsons )
119- right = right .drop (columns = jsons )
120- tm .assert_frame_equal (left , right , * args , ** kwargs )
82+ pass
12183
12284
12385class TestDtype (BaseJSON , base .BaseDtypeTests ):
12486 pass
12587
12688
12789class TestInterface (BaseJSON , base .BaseInterfaceTests ):
128- def test_custom_asserts (self ):
129- # This would always trigger the KeyError from trying to put
130- # an array of equal-length UserDicts inside an ndarray.
131- data = JSONArray (
132- [
133- collections .UserDict ({"a" : 1 }),
134- collections .UserDict ({"b" : 2 }),
135- collections .UserDict ({"c" : 3 }),
136- ]
137- )
138- a = pd .Series (data )
139- self .assert_series_equal (a , a )
140- self .assert_frame_equal (a .to_frame (), a .to_frame ())
141-
142- b = pd .Series (data .take ([0 , 0 , 1 ]))
143- msg = r"Series are different"
144- with pytest .raises (AssertionError , match = msg ):
145- self .assert_series_equal (a , b )
146-
147- with pytest .raises (AssertionError , match = msg ):
148- self .assert_frame_equal (a .to_frame (), b .to_frame ())
149-
15090 @pytest .mark .xfail (
15191 reason = "comparison method not implemented for JSONArray (GH-37867)"
15292 )
@@ -385,3 +325,66 @@ class TestComparisonOps(BaseJSON, base.BaseComparisonOpsTests):
385325
386326class TestPrinting (BaseJSON , base .BasePrintingTests ):
387327 pass
328+
329+
330+ def custom_assert_series_equal (left , right , * args , ** kwargs ):
331+ # NumPy doesn't handle an array of equal-length UserDicts.
332+ # The default assert_series_equal eventually does a
333+ # Series.values, which raises. We work around it by
334+ # converting the UserDicts to dicts.
335+ if left .dtype .name == "json" :
336+ assert left .dtype == right .dtype
337+ left = pd .Series (
338+ JSONArray (left .values .astype (object )), index = left .index , name = left .name
339+ )
340+ right = pd .Series (
341+ JSONArray (right .values .astype (object )),
342+ index = right .index ,
343+ name = right .name ,
344+ )
345+ tm .assert_series_equal (left , right , * args , ** kwargs )
346+
347+
348+ def custom_assert_frame_equal (left , right , * args , ** kwargs ):
349+ obj_type = kwargs .get ("obj" , "DataFrame" )
350+ tm .assert_index_equal (
351+ left .columns ,
352+ right .columns ,
353+ exact = kwargs .get ("check_column_type" , "equiv" ),
354+ check_names = kwargs .get ("check_names" , True ),
355+ check_exact = kwargs .get ("check_exact" , False ),
356+ check_categorical = kwargs .get ("check_categorical" , True ),
357+ obj = f"{ obj_type } .columns" ,
358+ )
359+
360+ jsons = (left .dtypes == "json" ).index
361+
362+ for col in jsons :
363+ custom_assert_series_equal (left [col ], right [col ], * args , ** kwargs )
364+
365+ left = left .drop (columns = jsons )
366+ right = right .drop (columns = jsons )
367+ tm .assert_frame_equal (left , right , * args , ** kwargs )
368+
369+
370+ def test_custom_asserts ():
371+ # This would always trigger the KeyError from trying to put
372+ # an array of equal-length UserDicts inside an ndarray.
373+ data = JSONArray (
374+ [
375+ collections .UserDict ({"a" : 1 }),
376+ collections .UserDict ({"b" : 2 }),
377+ collections .UserDict ({"c" : 3 }),
378+ ]
379+ )
380+ a = pd .Series (data )
381+ custom_assert_series_equal (a , a )
382+ custom_assert_frame_equal (a .to_frame (), a .to_frame ())
383+
384+ b = pd .Series (data .take ([0 , 0 , 1 ]))
385+ msg = r"Series are different"
386+ with pytest .raises (AssertionError , match = msg ):
387+ custom_assert_series_equal (a , b )
388+
389+ with pytest .raises (AssertionError , match = msg ):
390+ custom_assert_frame_equal (a .to_frame (), b .to_frame ())
0 commit comments