Skip to content

Commit ba871a6

Browse files
committed
TST: add a test for columns with nested strings
1 parent 71360af commit ba871a6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pandas/tests/test_frame.py

+33
Original file line numberDiff line numberDiff line change
@@ -12603,6 +12603,7 @@ def setUpClass(cls):
1260312603
cls.parser = 'pandas'
1260412604
cls.frame = _frame.copy()
1260512605

12606+
1260612607
class TestDataFrameQueryPythonPython(TestDataFrameQueryNumExprPython):
1260712608

1260812609
@classmethod
@@ -12611,6 +12612,7 @@ def setUpClass(cls):
1261112612
cls.engine = cls.parser = 'python'
1261212613
cls.frame = _frame.copy()
1261312614

12615+
1261412616
PARSERS = 'python', 'pandas'
1261512617
ENGINES = 'python', 'numexpr'
1261612618

@@ -12742,6 +12744,34 @@ def test_object_array_eq_ne(self):
1274212744
for parser, engine in product(PARSERS, ENGINES):
1274312745
yield self.check_object_array_eq_ne, parser, engine
1274412746

12747+
def check_query_with_nested_strings(self, parser, engine):
12748+
skip_if_no_ne(engine)
12749+
skip_if_no_pandas_parser(parser)
12750+
from pandas.compat import StringIO
12751+
raw = """id event timestamp
12752+
1 "page 1 load" 1/1/2014 0:00:01
12753+
1 "page 1 exit" 1/1/2014 0:00:31
12754+
2 "page 2 load" 1/1/2014 0:01:01
12755+
2 "page 2 exit" 1/1/2014 0:01:31
12756+
3 "page 3 load" 1/1/2014 0:02:01
12757+
3 "page 3 exit" 1/1/2014 0:02:31
12758+
4 "page 1 load" 2/1/2014 1:00:01
12759+
4 "page 1 exit" 2/1/2014 1:00:31
12760+
5 "page 2 load" 2/1/2014 1:01:01
12761+
5 "page 2 exit" 2/1/2014 1:01:31
12762+
6 "page 3 load" 2/1/2014 1:02:01
12763+
6 "page 3 exit" 2/1/2014 1:02:31
12764+
"""
12765+
df = pd.read_csv(StringIO(raw), sep=r'\s{2,}',
12766+
parse_dates=['timestamp'])
12767+
expected = df[df.event == '"page 1 load"']
12768+
res = df.query("""'"page 1 load"' in event""", parser=parser,
12769+
engine=engine)
12770+
tm.assert_frame_equal(expected, res)
12771+
12772+
def test_query_with_nested_string(self):
12773+
for parser, engine in product(PARSERS, ENGINES):
12774+
yield self.check_query_with_nested_strings, parser, engine
1274512775

1274612776
class TestDataFrameEvalNumExprPandas(tm.TestCase):
1274712777

@@ -12779,6 +12809,7 @@ def setUpClass(cls):
1277912809
cls.parser = 'python'
1278012810
skip_if_no_ne()
1278112811

12812+
1278212813
class TestDataFrameEvalPythonPandas(TestDataFrameEvalNumExprPandas):
1278312814

1278412815
@classmethod
@@ -12787,13 +12818,15 @@ def setUpClass(cls):
1278712818
cls.engine = 'python'
1278812819
cls.parser = 'pandas'
1278912820

12821+
1279012822
class TestDataFrameEvalPythonPython(TestDataFrameEvalNumExprPython):
1279112823

1279212824
@classmethod
1279312825
def setUpClass(cls):
1279412826
super(TestDataFrameEvalPythonPython, cls).tearDownClass()
1279512827
cls.engine = cls.parser = 'python'
1279612828

12829+
1279712830
if __name__ == '__main__':
1279812831
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
1279912832
exit=False)

0 commit comments

Comments
 (0)