Skip to content

BUG: loc setting NaN in an int column should upcast #4204

@hayd

Description

@hayd
Contributor

I think upcasting to float should occur here.

For example:

In [1]: df = pd.DataFrame([[0, 0]])

In [2]: df.loc[0] = np.nan

In [3]: df
Out[3]:
                     0                    1
0 -9223372036854775808 -9223372036854775808

Sometimes this is caught:

In [11]: df = pd.DataFrame([[0]])

In [12]: df.loc[0] = np.nan
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-92653b6a9ef8> in <module>()
----> 1 df.loc[0] = np.nan

/Users/234BroadWalk/pandas/core/indexing.pyc in __setitem__(self, key, value)
     86
     87         self._setitem_with_indexer(indexer, value)
---> 88
     89     def _has_valid_tuple(self, key):
     90         pass

/Users/234BroadWalk/pandas/core/indexing.pyc in _setitem_with_indexer(self, indexer, value)
    183             if np.prod(values.shape):
    184                 values[indexer] = value
--> 185
    186     def _align_series(self, indexer, ser):
    187         # indexer to assign Series can be tuple or scalar

ValueError: cannot convert float NaN to integer

Activity

jreback

jreback commented on Jul 11, 2013

@jreback
Contributor

this works in a mixed-frame, but the path for single dtype frame is different, sigh :(

jreback

jreback commented on Aug 16, 2013

@jreback
Contributor

closed by #3482

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselvesNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jreback@hayd

        Issue actions

          BUG: loc setting NaN in an int column should upcast · Issue #4204 · pandas-dev/pandas