Skip to content

Commit

Permalink
Merge pull request #641 from bccp/update-for-pandas-1.1
Browse files Browse the repository at this point in the history
Check all columns are defined in names.
  • Loading branch information
rainwoodman committed Sep 8, 2020
2 parents ce9d0fc + 78247fe commit f95af4c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nbodykit/io/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ def verify_data(path, names, nrows=10, **config):
"""
# read the first few lines to get the the dtype
try:
# first check no columns are missing to avoid silent data loss:
# https://github.com/pandas-dev/pandas/issues/26218
df = read_csv(path, nrows=nrows, **config)
if len(df.columns) != len(names):
raise ValueError("Number of columns does not match, excepting len(names) == %d" % len(df.columns))

df = read_csv(path, nrows=nrows, names=names, **config)

if df.isnull().sum().any():
Expand Down

0 comments on commit f95af4c

Please sign in to comment.