|
31 | 31 | from pandas.core.dtypes.common import (
|
32 | 32 | ensure_object, is_categorical_dtype, is_datetime64_dtype)
|
33 | 33 |
|
34 |
| -from pandas import DatetimeIndex, compat, isna, to_datetime, to_timedelta |
| 34 | +from pandas import ( |
| 35 | + DatetimeIndex, compat, concat, isna, to_datetime, to_timedelta) |
35 | 36 | from pandas.core.arrays import Categorical
|
36 | 37 | from pandas.core.base import StringMixin
|
37 | 38 | from pandas.core.frame import DataFrame
|
@@ -1572,7 +1573,7 @@ def read(self, nrows=None, convert_dates=None,
|
1572 | 1573 | data = DataFrame.from_dict(OrderedDict(data_formatted))
|
1573 | 1574 | del data_formatted
|
1574 | 1575 |
|
1575 |
| - self._do_convert_missing(data, convert_missing) |
| 1576 | + data = self._do_convert_missing(data, convert_missing) |
1576 | 1577 |
|
1577 | 1578 | if convert_dates:
|
1578 | 1579 | cols = np.where(lmap(lambda x: any(x.startswith(fmt)
|
@@ -1616,7 +1617,7 @@ def read(self, nrows=None, convert_dates=None,
|
1616 | 1617 |
|
1617 | 1618 | def _do_convert_missing(self, data, convert_missing):
|
1618 | 1619 | # Check for missing values, and replace if found
|
1619 |
| - |
| 1620 | + replacements = {} |
1620 | 1621 | for i, colname in enumerate(data):
|
1621 | 1622 | fmt = self.typlist[i]
|
1622 | 1623 | if fmt not in self.VALID_RANGE:
|
@@ -1646,8 +1647,14 @@ def _do_convert_missing(self, data, convert_missing):
|
1646 | 1647 | dtype = np.float64
|
1647 | 1648 | replacement = Series(series, dtype=dtype)
|
1648 | 1649 | replacement[missing] = np.nan
|
1649 |
| - |
1650 |
| - data[colname] = replacement |
| 1650 | + replacements[colname] = replacement |
| 1651 | + if replacements: |
| 1652 | + columns = data.columns |
| 1653 | + replacements = DataFrame(replacements) |
| 1654 | + data = concat([data.drop(replacements.columns, 1), |
| 1655 | + replacements], 1) |
| 1656 | + data = data[columns] |
| 1657 | + return data |
1651 | 1658 |
|
1652 | 1659 | def _insert_strls(self, data):
|
1653 | 1660 | if not hasattr(self, 'GSO') or len(self.GSO) == 0:
|
@@ -1712,7 +1719,7 @@ def _do_convert_categoricals(self, data, value_label_dict, lbllist,
|
1712 | 1719 | except ValueError:
|
1713 | 1720 | vc = Series(categories).value_counts()
|
1714 | 1721 | repeats = list(vc.index[vc > 1])
|
1715 |
| - repeats = '\n' + '-' * 80 + '\n'.join(repeats) |
| 1722 | + repeats = '-' * 80 + '\n' + '\n'.join(repeats) |
1716 | 1723 | raise ValueError('Value labels for column {col} are not '
|
1717 | 1724 | 'unique. The repeated labels are:\n'
|
1718 | 1725 | '{repeats}'
|
|
0 commit comments