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

Rework hdf output #11

merged 6 commits into from Jul 7, 2016

handle dtype mismatches in update col from series, update tests

  • Loading branch information...
bridwell committed Jul 5, 2016
commit fa560ee7f2911395cdf4e129699c4980b7a518f3
@@ -317,19 +317,30 @@ def column_type(self, column_name):
raise KeyError('column {!r} not found'.format(column_name))
def update_col_from_series(self, column_name, series):
def update_col_from_series(self, column_name, series, cast=False):
Update existing values in a column from another series.
Index values must match in both column and series.
Index values must match in both column and series. Optionally
casts data type to match the existing column.
column_name : str
series : panas.Series
case: bool, optional, default False
logger.debug('updating column {!r} in table {!r}'.format(
col_dtype = self.local[column_name].dtype
if series.dtype != col_dtype:
if cast:
series = series.astype(col_dtype)
err_msg = "Data type mismatch, existing:{}, update:{}"
err_msg = err_msg.format(col_dtype, series.dtype)
raise ValueError(err_msg)
self.local.loc[series.index, column_name] = series
def __len__(self):
@@ -356,9 +356,20 @@ def test_update_col(df):
wrapped['b'], pd.Series([7, 8, 9], index=df.index, name='b'))
wrapped.update_col_from_series('a', pd.Series([]))
a_dtype = wrapped['a'].dtype
# test 1 - cast the data type before the update
wrapped.update_col_from_series('a', pd.Series(dtype=a_dtype))
pdt.assert_series_equal(wrapped['a'], df['a'])
# test 2 - let the update method do the cast
wrapped.update_col_from_series('a', pd.Series(), True)
pdt.assert_series_equal(wrapped['a'], df['a'])
# test 3 - don't cast, should raise an error
with pytest.raises(ValueError):
wrapped.update_col_from_series('a', pd.Series())
wrapped.update_col_from_series('a', pd.Series([99], index=['y']))
wrapped['a'], pd.Series([1, 99, 3], index=df.index, name='a'))
ProTip! Use n and p to navigate between commits in a pull request.