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

Allow to write out lists in vertical orientation to Excel #11

Closed
fzumstein opened this Issue Apr 28, 2014 · 11 comments

Comments

Projects
None yet
3 participants
@fzumstein
Member

fzumstein commented Apr 28, 2014

This will be very handy for 1d arrays/lists. If you want to write out a 1d NumPy array in column orientation you currently have to do something like this for 1d arrays:

Range('A1').value = 1d_array[:,np.newaxis]

It should be easier like this:

Range('A1').vertical.value = 1d_array
@fzumstein

This comment has been minimized.

Member

fzumstein commented Jul 19, 2014

This should actually work for any input:

Range('A1').vertical.value = [[1,2],[3,4]]

should result in this:

screen shot 2014-07-19 at 20 12 25

anlogous for the horizontal property.

@fzumstein fzumstein modified the milestone: v0.2.3 Oct 6, 2014

@fzumstein fzumstein modified the milestones: v0.2.4, v0.2.3 Oct 13, 2014

@fzumstein

This comment has been minimized.

Member

fzumstein commented Oct 15, 2014

I guess this isn't doable in the suggested way. It had to work via a keyword argument. Not sure if that's the way to go.

@fzumstein fzumstein removed this from the v0.2.4 milestone Oct 15, 2014

@fzumstein fzumstein modified the milestone: v0.3.1 Dec 1, 2014

@fzumstein

This comment has been minimized.

Member

fzumstein commented Jan 7, 2015

Simple lists can easily be turned vertically like so: Range('A1').value = zip([1, 2, 3, 4]) for Python 2 or Range('A1').value = list(zip([1, 2, 3, 4])) for Python 3.

@rom1dep

This comment has been minimized.

rom1dep commented Apr 12, 2016

Is this released?
On my machine (anaconda 4), I get:

In [72]: xlwings.__version__
Out[72]: '0.7.1'
# v is a python list
# from the tests examples
In [73]: Range("Sheet1","C2").array(vertical=True).value=v
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-73-64e15862d345> in <module>()
----> 1 Range("Sheet1","C2").array(vertical=True).value=v

AttributeError: 'Range' object has no attribute 'array'

# the following leads to the same old behavior filling the data horizontally instead of vertically
In [74]: Range("Sheet1","C2").vertical.value=v
@fzumstein

This comment has been minimized.

Member

fzumstein commented Apr 12, 2016

The code that you are referencing is from a branch that has never been merged. It has been implemented as pointed out in the release note of v0.7.0:

Range('A1').options(transpose=True).value = [1, 2, 3]

@fzumstein fzumstein changed the title from Allow assignment to .vertical (and .horizontal) property to Allow to write out list in vertical orientation to Excel Apr 12, 2016

@fzumstein fzumstein changed the title from Allow to write out list in vertical orientation to Excel to Allow to write out lists in vertical orientation to Excel Apr 12, 2016

@rom1dep

This comment has been minimized.

rom1dep commented Apr 12, 2016

Oh, that was confusing. Thanks for the clarification!
I liked the simplicity of using Range.vertical.value as per your original post. It appears to me as the best (i.e. the most consistent and less surprising) UI to write a one-dimensional array vertically, which is a fairly common operation.

Is there any ongoing work towards that or is the subject considered closed already?

@fzumstein

This comment has been minimized.

Member

fzumstein commented Apr 12, 2016

It's closed, yes. It's all happening in options now, it's in fact more consistent with the rest of the API since v0.7.0. You can't set nested properties, so the syntax you want is not possible.

@rom1dep

This comment has been minimized.

rom1dep commented Apr 14, 2016

OK, fair enough.
Then, allowing the use of Range.vertical as a setter seems to be a huge footgun which deserves being clearly mentioned in the doc (because user will definitely expect its data to be laid vertically when using R.vertical).

I'm still thinking that an abstraction for orientation selection (or more precisely, making its use mandatory and/or removing the R.horizontal/R.vertical attributes) is the best way forward.

@fzumstein

This comment has been minimized.

Member

fzumstein commented Apr 14, 2016

yeah, you got a point there. We thought of changing the implementation from properties to methods. This should do the trick and also align the syntax with the one used in options, something like: Range('A1').expand('vertical').value instead of Range('A1').vertical.value

@fzumstein fzumstein reopened this Apr 14, 2016

@fzumstein fzumstein modified the milestones: short list, v0.7.0 Apr 14, 2016

@denfromufa

This comment has been minimized.

denfromufa commented May 25, 2016

+1

@fzumstein fzumstein modified the milestones: bluesky, short list May 25, 2016

@fzumstein

This comment has been minimized.

Member

fzumstein commented Jul 27, 2016

Finally decided to refactor .table etc. into .expand('table'). Orientation to be handled by .transpose() as previously. Some reasoning:

It's a bit like the print statement-to-function change in PY3:

  • expanding a range is an action rather than a property
  • it allows to include parameters further down the road like skip_empty_rows=1
  • users were wrongly expecting xw.Range('A1').vertical.value = [1, 2, 3] to act as transposing and write things out in vertical orientation
  • 'table' will be default, so not really more typing required: xw.Range('A1').table vs xw.Range('A1').expand()
  • It'll correspond to the planned expand=True feature for UDFs

ping @gdementen

@fzumstein fzumstein closed this Aug 1, 2016

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