Skip to content

Commit caaab82

Browse files
committed
TST: Fix intersect and except tests
1 parent 40c59ff commit caaab82

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

dataframe_sql/tests/pandas_sql_functionality_test.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ def test_union_all(pandas_frame1_for_set_ops, pandas_frame2_for_set_ops):
566566
tm.assert_frame_equal(pandas_frame, my_frame)
567567

568568

569-
@ibis_not_implemented
570569
def test_intersect_distinct(pandas_frame1_for_set_ops, pandas_frame2_for_set_ops):
571570
"""
572571
Test union distinct in queries
@@ -576,19 +575,18 @@ def test_intersect_distinct(pandas_frame1_for_set_ops, pandas_frame2_for_set_ops
576575
"""
577576
select * from forest_fires order by wind desc limit 5
578577
intersect distinct
579-
select * from forest_fires order by wind desc limit 3
578+
select * from forest_fires order by wind asc limit 5
580579
"""
581580
)
582581
pandas_frame = merge(
583582
left=pandas_frame1_for_set_ops,
584583
right=pandas_frame2_for_set_ops,
585584
how="inner",
586585
on=list(pandas_frame1_for_set_ops.columns),
587-
)
586+
).reset_index(drop=True)
588587
tm.assert_frame_equal(pandas_frame, my_frame)
589588

590589

591-
@ibis_not_implemented()
592590
def test_except_distinct(pandas_frame1_for_set_ops, pandas_frame2_for_set_ops):
593591
"""
594592
Test except distinct in queries
@@ -598,20 +596,16 @@ def test_except_distinct(pandas_frame1_for_set_ops, pandas_frame2_for_set_ops):
598596
"""
599597
select * from forest_fires order by wind desc limit 5
600598
except distinct
601-
select * from forest_fires order by wind desc limit 3
599+
select * from forest_fires order by wind asc limit 5
602600
"""
603601
)
604-
pandas_frame = (
605-
pandas_frame1_for_set_ops[
606-
~pandas_frame1_for_set_ops.isin(pandas_frame2_for_set_ops).all(axis=1)
607-
]
608-
.drop_duplicates()
609-
.reset_index(drop=True)
602+
merged = pandas_frame1_for_set_ops.merge(
603+
pandas_frame2_for_set_ops, on=list(pandas_frame1_for_set_ops.columns), how='outer', indicator=True
610604
)
605+
pandas_frame = merged[merged["_merge"] != "both"].drop("_merge", 1).drop_duplicates().reset_index(drop=True)
611606
tm.assert_frame_equal(pandas_frame, my_frame)
612607

613608

614-
@ibis_not_implemented
615609
def test_except_all(pandas_frame1_for_set_ops, pandas_frame2_for_set_ops):
616610
"""
617611
Test except distinct in queries
@@ -621,12 +615,13 @@ def test_except_all(pandas_frame1_for_set_ops, pandas_frame2_for_set_ops):
621615
"""
622616
select * from forest_fires order by wind desc limit 5
623617
except all
624-
select * from forest_fires order by wind desc limit 3
618+
select * from forest_fires order by wind asc limit 5
625619
"""
626620
)
627-
pandas_frame = pandas_frame1_for_set_ops[
628-
~pandas_frame1_for_set_ops.isin(pandas_frame2_for_set_ops).all(axis=1)
629-
].reset_index(drop=True)
621+
merged = pandas_frame1_for_set_ops.merge(
622+
pandas_frame2_for_set_ops, on=list(pandas_frame1_for_set_ops.columns), how='outer', indicator=True
623+
)
624+
pandas_frame = merged[merged["_merge"] != "both"].drop("_merge", 1).reset_index(drop=True)
630625
tm.assert_frame_equal(pandas_frame, my_frame)
631626

632627

0 commit comments

Comments
 (0)