Use cssdecl package for resolving CSS
State: closed

Uses dependency on an external project instead of having local code to handle the resolution of DataFrame.style CSS to interpretable atoms. This allows reuse of that code and relatively independent development of more complete CSS2.2 coverage.

 - [x] ~~closes #xxxx~~ N/A
 - [x] tests added / passed
 - [x] passes ``git diff upstream/master --name-only -- '*.py' | flake8 --diff``
 - [x] ~~whatsnew entry~~ N/A


Labels:
name: Enhancement
name: IO Excel
description: read_excel, to_excel

Comments:
Do get this working, does cssdecl need uploading to the pandas channel? Currently it's at https://github.com/jnothman/cssdecl

@jnothman nothing to do with a channel. your package should be pip installable.
Are you certain? it is definitely pip installable... and the error messages in travis are like:
```
PackageNotFoundError: Package missing in current osx-64 channels: 
  - cssdecl
```
You should be able to add it to `ci/requirements-*.pip`
Thanks

On 1 May 2017 at 23:49, Tom Augspurger <notifications@github.com> wrote:

> You should be able to add it to ci/requirements-*.pip
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/16170#issuecomment-298336291>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAEz66esBFa0ARy6z52c5zYmhB9obmCpks5r1eLbgaJpZM4NMOkW>
> .
>

Test failure appears unrelated
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=h1) Report
> Merging [#16170](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/a7a0574a0bcb8a4c65ed7f5006972e24f90ae3df?src=pr&el=desc) will **decrease** coverage by `0.21%`.
> The diff coverage is `66.66%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/16170/graphs/tree.svg?src=pr&token=eZ4WkYLtcO&width=650&height=150)](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #16170      +/-   ##
==========================================
- Coverage   90.86%   90.64%   -0.22%     
==========================================
  Files         162      161       -1     
  Lines       50819    50718     -101     
==========================================
- Hits        46177    45975     -202     
- Misses       4642     4743     +101
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.42% <66.66%> (-0.23%)` | :arrow_down: |
| #single | `40.36% <0%> (+0.02%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/excel.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZXhjZWwucHk=) | `66.55% <66.66%> (-30.09%)` | :arrow_down: |
| [pandas/io/excel.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2lvL2V4Y2VsLnB5) | `79.73% <0%> (-0.89%)` | :arrow_down: |
| [pandas/io/formats/style.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvc3R5bGUucHk=) | `96.06% <0%> (-0.31%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `78.88% <0%> (-0.19%)` | :arrow_down: |
| [pandas/compat/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fX2luaXRfXy5weQ==) | `62.22% <0%> (-0.11%)` | :arrow_down: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `91.63% <0%> (ø)` | :arrow_up: |
| [pandas/core/config\_init.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29uZmlnX2luaXQucHk=) | `94.52% <0%> (+0.23%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=footer). Last update [a7a0574...fa9ca9f](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=h1) Report
> Merging [#16170](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/0ea0f25bfb920cd0f58872dc95913a7aa9c0c3da?src=pr&el=desc) will **decrease** coverage by `0.24%`.
> The diff coverage is `57.14%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/16170/graphs/tree.svg?token=eZ4WkYLtcO&width=650&src=pr&height=150)](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #16170      +/-   ##
==========================================
- Coverage   90.38%   90.13%   -0.25%     
==========================================
  Files         161      160       -1     
  Lines       50916    50807     -109     
==========================================
- Hits        46021    45797     -224     
- Misses       4895     5010     +115
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `87.9% <57.14%> (-0.24%)` | :arrow_down: |
| #single | `40.25% <0%> (-0.08%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/excel.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZXhjZWwucHk=) | `43.37% <57.14%> (-29.78%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/io/excel.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2lvL2V4Y2VsLnB5) | `57.84% <0%> (-3.85%)` | :arrow_down: |
| [pandas/io/formats/style.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvc3R5bGUucHk=) | `95.64% <0%> (-0.28%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.68% <0%> (-0.1%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.05% <0%> (+1.81%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=footer). Last update [0ea0f25...2d83322](https://codecov.io/gh/pandas-dev/pandas/pull/16170?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

this PR needs to wait for 0.21.0 fyi. would like to have the dep filled out / more testing and docs.
okay. what do you mean by "the dep filled out"?

On 3 May 2017 9:45 am, "Jeff Reback" <notifications@github.com> wrote:

> this PR needs to wait for 0.21.0 fyi. would like to have the dep filled
> out / more testing and docs.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/16170#issuecomment-298791982>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAEz6wKDjowvs1IArJA27SSR6r67iDklks5r18AogaJpZM4NMOkW>
> .
>

@jnothman what I mean is that this dep is used, tested on CI, has docs etc. Yes I know you carved it out of pandas, but it needs to be a properly supported (and versioned package). Its not a big deal to do that (and it kind of forces you to make it user friendly). We are going to start pushing to 0.21.0 soon anyhow (right after the release of 0.20.0)
Yes, I thought you meant CI and docs. I can't make it used.

On 3 May 2017 at 10:29, Jeff Reback <notifications@github.com> wrote:

> @jnothman <https://github.com/jnothman> what I mean is that this dep is
> used, tested on CI, has docs etc. Yes I know you carved it out of pandas,
> but it needs to be a properly supported (and versioned package). Its not a
> big deal to do that (and it kind of forces you to make it user friendly).
> We are going to start pushing to 0.21.0 soon anyhow (right after the
> release of 0.20.0)
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/16170#issuecomment-298797720>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAEz6wAHywafI42LMjJNTtQUquXxlczxks5r18pbgaJpZM4NMOkW>
> .
>

see http://cssdecl.readthedocs.io, http://github.com/jnothman/cssdecl

this looks reasonable. pls rebase and ping when ready.
add a note in api-breaking in 0.21.0
Done apart from directory restructure.
So is this okay for now?
re conda-forge, I'm still learning the ropes a little, but have at least built a package and posted it to my own channel.
> re conda-forge, I'm still learning the ropes a little, but have at least built a package and posted it to my own channel.

yeah you can submit a recipe to conda-forge and then it will create a feedstock. should be pretty easy for this. not required, but nice.
@TomAugspurger ?
Green, @jreback
can you rebase on master. skips were not printing correctly, so now fixed.
xlsxwriter support requires #16149

On 12 May 2017 9:37 am, "Jeff Reback" <notifications@github.com> wrote:

> *@jreback* commented on this pull request.
> ------------------------------
>
> In doc/source/whatsnew/v0.21.0.txt
> <https://github.com/pandas-dev/pandas/pull/16170#discussion_r116121933>:
>
> > @@ -34,6 +34,7 @@ Other Enhancements
>  Backwards incompatible API changes
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> +- The ``DataFrame.style.to_excel()`` styled Excel export functionality now requires an external dependency, `cssdecl <http://pypi.python.org/pypi/cssdecl>`_.
>
> doesn't this add export to xlxswriter as compared to 0.20.1? if so pls add
> *another* note in Other Enhancements section. (maybe also need to update
> the io.rst docs?)
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/16170#discussion_r116121933>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAEz6w-2Do0NKWQs2SxeBn5E3W_xMwe_ks5r45PagaJpZM4NMOkW>
> .
>

PR number added to what's new. Master merged.

cssdecl's next release (and I'll try to package it in conda-forge too) should at least handle some CSS cleaning better and handle `border: 1px solid red` and similar shorthands.
I've just been informed of the package weasyprint which does everything cssdecl should do, it seems. My literature review want good enough. Let me look a bit further into whether we can use that rather than reinvent the wheel. Closing for now.