-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
COMPAT: reading json with lines=True from s3, xref #17200 #17201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8255cd0
caa3c80
4709251
a042e3c
0c164e7
ac99133
125f049
533d404
c7f13b8
17973a1
2ae5a9d
38f043b
1d03d7a
78ee720
9d7e75b
b21401b
6979fb8
bb600cb
5b036ec
c5c4d07
f1122ca
b913972
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,11 @@ | |
from pandas.compat import (range, lrange, StringIO, | ||
OrderedDict, is_platform_32bit) | ||
import os | ||
import boto3 | ||
|
||
import numpy as np | ||
from pandas import (Series, DataFrame, DatetimeIndex, Timestamp, | ||
read_json, compat) | ||
from datetime import timedelta | ||
from moto import mock_s3 | ||
moto = pytest.importorskip("moto") | ||
import pandas as pd | ||
|
||
from pandas.util.testing import (assert_almost_equal, assert_frame_equal, | ||
|
@@ -993,12 +991,22 @@ def test_read_inline_jsonl(self): | |
expected = DataFrame([[1, 2], [1, 2]], columns=['a', 'b']) | ||
assert_frame_equal(result, expected) | ||
|
||
@mock_s3 | ||
def test_read_s3_jsonl(self): | ||
# GH17200 | ||
@pytest.yield_fixture(scope="function") | ||
def testbucket_conn(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't looked, but can you use the fixture defined in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TomAugspurger I was working on trying to reuse the code here. In order to reuse across moduled I'd probably need to move the This may also entail changing how pointing to the data files that are mock-uploaded works since that code would no longer live in |
||
""" Fixture for test_read_s3_jsonl""" | ||
boto3 = pytest.importorskip('boto3') | ||
moto.mock_s3().start() # Start and stop mocking only once, surrounding the test run | ||
# to ensure single context is kept. | ||
|
||
conn = boto3.client('s3') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This setup stuff can be moved to a pytest fixture. Something like @mock_s3
@pytest.fixture
def testbucket():
"""Fixture for ..."""
conn = ... Then your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also move the boto3 import here and use |
||
conn.create_bucket(Bucket='testbucket') | ||
conn.put_object(Body=b'{"a": 1, "b": 2}\n{"b":2, "a" :1}\n', Key='items.jsonl', Bucket='testbucket') | ||
yield conn | ||
|
||
moto.mock_s3().stop() | ||
|
||
def test_read_s3_jsonl(self, testbucket_conn): | ||
# GH17200 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a |
||
testbucket_conn.put_object(Body=b'{"a": 1, "b": 2}\n{"b":2, "a" :1}\n', Key='items.jsonl', Bucket='testbucket') | ||
|
||
result = read_json('s3://testbucket/items.jsonl', lines=True) | ||
expected = DataFrame([[1, 2], [1, 2]], columns=['a', 'b']) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will skip the entire module if moto isn't found. I think some of these tests can run without moto, so do this skip inside each test that needs moto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be removed, moto is now always installed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added as a regular import