-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Google Cloud Storage support using gcsfs
- Loading branch information
Showing
18 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ dependencies: | |
- beautifulsoup4 | ||
- bottleneck | ||
- dateutil | ||
- gcsfs | ||
- html5lib | ||
- jinja2=2.8 | ||
- lxml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
blacklist = { | ||
'bs4', | ||
'gcsfs', | ||
'html5lib', | ||
'ipython', | ||
'jinja2' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ channels: | |
dependencies: | ||
- beautifulsoup4 | ||
- cython | ||
- gcsfs | ||
- html5lib | ||
- ipython | ||
- jinja2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ channels: | |
dependencies: | ||
- beautifulsoup4 | ||
- cython | ||
- gcsfs | ||
- html5lib | ||
- ipython | ||
- jinja2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ blosc | |
bottleneck | ||
fastparquet | ||
feather-format | ||
gcsfs | ||
html5lib | ||
ipython>=5.6.0 | ||
ipykernel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ blosc | |
bottleneck | ||
fastparquet | ||
feather-format | ||
gcsfs | ||
html5lib | ||
ipython>=5.6.0 | ||
ipykernel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ pytest>=3.1 | |
python-dateutil>=2.5.0 | ||
pytz | ||
setuptools>=24.2.0 | ||
sphinx | ||
sphinx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ channels: | |
dependencies: | ||
- beautifulsoup4 | ||
- cython | ||
- gcsfs | ||
- html5lib | ||
- lxml | ||
- matplotlib | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ dependencies: | |
- dask | ||
- fastparquet | ||
- feather-format | ||
- gcsfs | ||
- geopandas | ||
- html5lib | ||
- ipython | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" GCS support for remote file interactivity """ | ||
try: | ||
import gcsfs | ||
except ImportError: | ||
raise ImportError("The gcsfs library is required to handle GCS files") | ||
|
||
|
||
def get_filepath_or_buffer(filepath_or_buffer, encoding=None, | ||
compression=None, mode=None): | ||
|
||
if mode is None: | ||
mode = 'rb' | ||
|
||
fs = gcsfs.GCSFileSystem() | ||
filepath_or_buffer = fs.open(filepath_or_buffer, mode) | ||
return filepath_or_buffer, None, compression, True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pytest | ||
|
||
from pandas import DataFrame, read_csv | ||
from pandas.compat import BytesIO | ||
from pandas.io.common import is_gcs_url | ||
from pandas.util import _test_decorators as td | ||
|
||
|
||
def test_is_gcs_url(): | ||
assert is_gcs_url("gcs://pandas/somethingelse.com") | ||
assert is_gcs_url("gs://pandas/somethingelse.com") | ||
assert not is_gcs_url("s3://pandas/somethingelse.com") | ||
|
||
|
||
@td.skip_if_no('gcsfs') | ||
def test_read_csv_gcs(): | ||
try: | ||
from unittest.mock import patch | ||
except ImportError: | ||
from mock import patch | ||
|
||
with patch('gcsfs.GCSFileSystem') as MockFileSystem: | ||
instance = MockFileSystem.return_value | ||
instance.open.return_value = BytesIO(b'a,b\n1,2\n3,4') | ||
df = read_csv('gs://test/test.csv') | ||
|
||
assert isinstance(df, DataFrame) | ||
assert len(df == 2) | ||
assert all(df.columns == ['a', 'b']) | ||
|
||
|
||
@td.skip_if_no('gcsfs') | ||
def test_gcs_get_filepath_or_buffer(): | ||
try: | ||
from unittest.mock import patch | ||
except ImportError: | ||
from mock import patch | ||
|
||
with patch('pandas.io.gcs.get_filepath_or_buffer') as MockGetFilepath: | ||
MockGetFilepath.return_value = (BytesIO(b'a,b\n1,2\n3,4'), None, None, | ||
False) | ||
df = read_csv('gs://test/test.csv') | ||
|
||
assert isinstance(df, DataFrame) | ||
assert len(df == 2) | ||
assert all(df.columns == ['a', 'b']) | ||
assert MockGetFilepath.called | ||
|
||
|
||
@pytest.mark.skipif(td.safe_import('gcsfs'), | ||
reason='Only check when gcsfs not installed') | ||
def test_gcs_not_present_exception(): | ||
with pytest.raises(ImportError) as e: | ||
read_csv('gs://test/test.csv') | ||
assert 'gcsfs library is required' in str(e.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters