Skip to content
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

Update read_table #362

Merged
merged 4 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datascience/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def read_table(cls, filepath_or_buffer, *args, **vargs):
vargs['sep'] = ','
except AttributeError:
pass
df = pandas.read_table(filepath_or_buffer, *args, **vargs)
df = pandas.read_csv(filepath_or_buffer, *args, **vargs)
return cls.from_df(df)

def _with_columns(self, columns):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,3 +1641,11 @@ def test_url_parse():
with pytest.raises(ValueError):
url = 'https://data8.berkeley.edu/something/something/dark/side'
Table.read_table(url)

def test_read_table():
"""Test that Tables reads a csv file."""
assert isinstance(Table().read_table("tests/us-unemployment.csv"), Table)
assert isinstance(Table().read_table("tests/us-unemployment-copy"), Table)
assert isinstance(Table().read_table("tests/us-unemployment.txt"), Table)
assert isinstance(Table().read_table("https://raw.githubusercontent.com/data-8/textbook/gh-pages/data/deflategate.csv"), Table)

51 changes: 51 additions & 0 deletions tests/us-unemployment-copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
State,Unemployment
AL,7.1
AK,6.8
AZ,8.1
AR,7.2
CA,10.1
CO,7.7
CT,8.4
DE,7.1
FL,8.2
GA,8.8
HI,5.4
ID,6.6
IL,8.8
IN,8.4
IA,5.1
KS,5.6
KY,8.1
LA,5.9
ME,7.2
MD,6.8
MA,6.7
MI,9.1
MN,5.6
MS,9.1
MO,6.7
MT,5.8
NE,3.9
NV,10.3
NH,5.7
NJ,9.6
NM,6.8
NY,8.4
NC,9.4
ND,3.2
OH,6.9
OK,5.2
OR,8.5
PA,8
RI,10.1
SC,8.8
SD,4.4
TN,7.8
TX,6.4
UT,5.5
VT,5
VA,5.8
WA,7.8
WV,7.5
WI,6.8
WY,5.1
51 changes: 51 additions & 0 deletions tests/us-unemployment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
State Unemployment
AL 7.1
AK 6.8
AZ 8.1
AR 7.2
CA 10.1
CO 7.7
CT 8.4
DE 7.1
FL 8.2
GA 8.8
HI 5.4
ID 6.6
IL 8.8
IN 8.4
IA 5.1
KS 5.6
KY 8.1
LA 5.9
ME 7.2
MD 6.8
MA 6.7
MI 9.1
MN 5.6
MS 9.1
MO 6.7
MT 5.8
NE 3.9
NV 10.3
NH 5.7
NJ 9.6
NM 6.8
NY 8.4
NC 9.4
ND 3.2
OH 6.9
OK 5.2
OR 8.5
PA 8
RI 10.1
SC 8.8
SD 4.4
TN 7.8
TX 6.4
UT 5.5
VT 5
VA 5.8
WA 7.8
WV 7.5
WI 6.8
WY 5.1