Skip to content

Commit 95a8356

Browse files
author
MarcoGorelli
committed
[skip ci] slicing
1 parent cab156e commit 95a8356

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

web/pandas/pdeps/0005-no-default-index-mode.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,33 @@ Out[11]: NoRowIndex(len=4)
126126

127127
Appending anything other than another ``NoRowIndex`` would raise.
128128

129+
### Slicing a ``NoRowIndex``
130+
131+
If one has a ``DataFrame`` with ``NoRowIndex``, then one would expect that a slice of it would still have
132+
a ``NoRowIndex``. This could be accomplished with:
133+
134+
If a slice of length ``x`` is taken from a ``NoRowIndex`` of length ``y``, then one gets a
135+
``NoRowIndex`` of length ``x``. Label-based slicing would not be allowed.
136+
137+
Example:
138+
139+
```python
140+
In [12]: df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}, index=NoRowIndex(3))
141+
142+
In [13]: df.loc[df['a']>1, 'b']
143+
Out[13]:
144+
5
145+
6
146+
Name: b, dtype: int64
147+
148+
In [14]: df.loc[df['a']>1, 'b'].index
149+
Out[14]: NoRowIndex(len=2)
150+
151+
In [15]: df.loc[0, 'b']
152+
---------------------------------------------------------------------------
153+
IndexError: Cannot use label-based indexing on NoRowIndex!
154+
```
155+
129156
### 2. DataFrameFormatter and SeriesFormatter changes
130157

131158
When printing an object with a ``NoIndex``, then the row labels wouldn't be shown:

0 commit comments

Comments
 (0)