Skip to content

CLN: move common printing utilties to pandas.io.formats.printing #21234

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

Merged
merged 2 commits into from
May 29, 2018

Conversation

jreback
Copy link
Contributor

@jreback jreback commented May 28, 2018

No description provided.

@jreback jreback added Output-Formatting __repr__ of pandas objects, to_string Clean ExtensionArray Extending pandas with custom dtypes or arrays. labels May 28, 2018
@jreback jreback added this to the 0.24.0 milestone May 28, 2018
@jreback
Copy link
Contributor Author

jreback commented May 28, 2018

these are really useful for ExtensionArrays to avoid re-inventing the wheel on repr. IIRC @TomAugspurger this was a sore point in creating IntervalArray.

@jreback
Copy link
Contributor Author

jreback commented May 28, 2018

e.g. get this (truncation, justification and line wrapping) on IntegerArray with no work

In [1]: pd.Series([1,2,np.nan]*20,dtype='Int8').values
Out[1]: 
IntegerArray([1, 2, nan, 1, 2, nan, 1, 2, nan, 1, 2, nan, 1, 2, nan, 1, 2, nan,
              1, 2, nan, 1, 2, nan, 1, 2, nan, 1, 2, nan, 1, 2, nan, 1, 2, nan,
              1, 2, nan, 1, 2, nan, 1, 2, nan, 1, 2, nan, 1, 2, nan, 1, 2, nan,
              1, 2, nan, 1, 2, nan],
             dtype='Int64')

In [2]: pd.Series([1,2,np.nan]*50,dtype='Int8').values
Out[2]: 
IntegerArray([1, 2, nan, 1, 2, nan, 1, 2, nan, 1,
              ...
              nan, 1, 2, nan, 1, 2, nan, 1, 2, nan],
             dtype='Int64', length=150)

with this code (can consider adding this as a function somewhere as well)

    def __repr__(self):
        """
        Return a string representation for this object.

        Invoked by unicode(df) in py2 only. Yields a Unicode String in both
        py2/py3.
        """
        klass = self.__class__.__name__
        data = format_object_summary(self, default_pprint, False, name=klass)
        attrs = format_object_attrs(self)
        space = " "

        prepr = (u(",%s") %
                 space).join(u("%s=%s") % (k, v) for k, v in attrs)

        res = u("%s(%s%s)") % (klass, data, prepr)

        return res

@codecov
Copy link

codecov bot commented May 29, 2018

Codecov Report

Merging #21234 into master will decrease coverage by <.01%.
The diff coverage is 97.53%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21234      +/-   ##
==========================================
- Coverage   91.84%   91.84%   -0.01%     
==========================================
  Files         153      153              
  Lines       49506    49512       +6     
==========================================
+ Hits        45467    45472       +5     
- Misses       4039     4040       +1
Flag Coverage Δ
#multiple 90.23% <97.53%> (-0.01%) ⬇️
#single 41.88% <79.01%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/base.py 96.61% <100%> (-0.08%) ⬇️
pandas/io/formats/printing.py 92.55% <97.33%> (+3.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 36c1f6b...7e5dfcc. Read the comment docs.

@jreback jreback merged commit b2eec25 into pandas-dev:master May 29, 2018
david-liu-brattle-1 pushed a commit to david-liu-brattle-1/pandas that referenced this pull request Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean ExtensionArray Extending pandas with custom dtypes or arrays. Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant