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

BUG: Formatting of an index that has nan was inconsistent or wrong #3034

Merged
merged 1 commit into from
Mar 13, 2013

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Mar 13, 2013

Formatting of an index that has nan was inconsistent or wrong,
(would fill from last value), closes GH #2850

Also changed in test_format.py/test_index

  1. printing of 'nan' rather than the na_rep (NaN) is inconcsistent
    with everywhere else
  2. a 'None' in the index is defacto treated as NaN, is this wrong?

@jreback
Copy link
Contributor Author

jreback commented Mar 13, 2013

@y-p when you have a chance, can you give this a look-see

@jreback
Copy link
Contributor Author

jreback commented Mar 13, 2013

updated
cleaner now

@ghost
Copy link

ghost commented Mar 13, 2013

👍

@ghost
Copy link

ghost commented Mar 13, 2013

Want to fix up pprint_thing or shall I?

@jreback
Copy link
Contributor Author

jreback commented Mar 13, 2013

well that's the thing, when is pprint_thing supposed to hit None?

@ghost
Copy link

ghost commented Mar 13, 2013

None? I don't follow.

@jreback
Copy link
Contributor Author

jreback commented Mar 13, 2013

what I meant was

pprint_thing(x)
where x is None

is this ever called? (i know it was called
on an index that had a None in it) - are there any valid
cases where this SHOULD be called with None?

I don't see an issue with pprint_thing like it is

@ghost
Copy link

ghost commented Mar 13, 2013

I was thinking of

In [73]: pd.core.common.pprint_thing(pd.Series([1,2,nan]))
Out[73]: u'[1.0, 2.0, nan]'

But, apperantly the repr/to_string methods take care of that,
so no need.

pprint_thing is mutually recursive with pprint_seq, so pprint_thing(None)
is possible. I made sure None printed as '', so there must have been some case
I can't for the life of me remember now.

In [77]: pd.core.common.pprint_thing([1,2,None])
Out[77]: u'[1, 2, ]'

I'm sure it justifies that. at least I hope it does.

@jreback
Copy link
Contributor Author

jreback commented Mar 13, 2013

ahh yes
that makes sense

the case I found was printing of a None index as ''
which I think should be illegal; prints as NaN now (and does a regular nan in an index)

so are we printing NaN or nan ?
is index different that values?

@ghost
Copy link

ghost commented Mar 13, 2013

show me a test case., what is a "None index"?

In [80]: pd.core.common.pprint_thing(pd.Index([]))
Out[80]: u'[]'

I think in normal use where the question of how nans are printed arises,
pprint_thing is not used directly and upper layers ensure proper behaviour.

in general. an index is a sequence like any other as far as pprint is concerned.

@@ -351,12 +351,13 @@ def test_format(self):
# 2845
index = Index([1, 2.0+3.0j, np.nan])
formatted = index.format()
expected = [str(index[0]), str(index[1]), str(index[2])]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here are the 2 cases

first one prints 'nan', but I think we elsewhere print 'NaN'
2nd prints '' (nothing), but I think that's wrong

@jreback
Copy link
Contributor Author

jreback commented Mar 13, 2013

I marked the 2 tests I changed in test_index

@ghost
Copy link

ghost commented Mar 13, 2013

Should be fine to change pp to print 'None' as 'None' in general. (at least
I can't remember a reason not to).

Whether None should be interpreted as None or NaN, would
mean adding a mode to pprint_seq and specializing it's invocation
from pprint_thing based on sequence type (ndarrays supporting nans).

Alternatively, since other objects print nans correcty the other stringify method
must be jumping through hoops that the Index class stringify does not.
so could just add that to Index repr()

edit: which is what you've done.

…g (would fill from

     other values), (GH2850_)

BUG: issue in test_index.py/test_format
       1) printing of 'nan' rather than the na_rep (NaN) is inconcistent
          with everywhere else
       2) a 'None' in the index is defacto treated as NaN, is this wrong?

CLN: constistency among index for NaN/NaT values
jreback added a commit that referenced this pull request Mar 13, 2013
BUG:  Formatting of an index that has nan was inconsistent or wrong
@jreback jreback merged commit 43d9f56 into pandas-dev:master Mar 13, 2013
@ghost ghost mentioned this pull request Mar 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant