Skip to content

Commit f036b93

Browse files
ENH Recognize 's3n' and 's3a' as an S3 address
1 parent e8d4243 commit f036b93

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

doc/source/whatsnew/v0.17.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ Other enhancements
467467

468468
- ``pd.read_csv`` can now read bz2-compressed files incrementally, and the C parser can read bz2-compressed files from AWS S3 (:issue:`11070`, :issue:`11072`).
469469

470+
- In ``pd.read_csv``, recognize "s3n://" and "s3a://" URLs as designating S3 file storage (:issue:`11070`, :issue:`11071`).
470471

471472
.. _whatsnew_0170.api:
472473

pandas/io/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def _is_url(url):
6666

6767

6868
def _is_s3_url(url):
69-
"""Check for an s3 url"""
69+
"""Check for an s3, s3n, or s3a url"""
7070
try:
71-
return parse_url(url).scheme == 's3'
71+
return parse_url(url).scheme in ['s3', 's3n', 's3a']
7272
except:
7373
return False
7474

pandas/io/tests/test_parsers.py

+16
Original file line numberDiff line numberDiff line change
@@ -4253,6 +4253,22 @@ def test_parse_public_s3_bucket(self):
42534253
nt.assert_false(df.empty)
42544254
tm.assert_frame_equal(pd.read_csv(tm.get_data_path('tips.csv')), df)
42554255

4256+
@tm.network
4257+
def test_parse_public_s3n_bucket(self):
4258+
# Read from AWS s3 as "s3n" URL
4259+
df = pd.read_csv('s3n://pandas-test/tips.csv', nrows=10)
4260+
self.assertTrue(isinstance(df, pd.DataFrame))
4261+
self.assertFalse(df.empty)
4262+
tm.assert_frame_equal(pd.read_csv(tm.get_data_path('tips.csv')).iloc[:10], df)
4263+
4264+
@tm.network
4265+
def test_parse_public_s3a_bucket(self):
4266+
# Read from AWS s3 as "s3a" URL
4267+
df = pd.read_csv('s3a://pandas-test/tips.csv', nrows=10)
4268+
self.assertTrue(isinstance(df, pd.DataFrame))
4269+
self.assertFalse(df.empty)
4270+
tm.assert_frame_equal(pd.read_csv(tm.get_data_path('tips.csv')).iloc[:10], df)
4271+
42564272
@tm.network
42574273
def test_s3_fails(self):
42584274
import boto

0 commit comments

Comments
 (0)