Skip to content

Commit cb47484

Browse files
committed
Merge branch 'master' of git://github.com/pydata/pandas into panelnd
2 parents 77aa4f6 + 4519310 commit cb47484

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+7003
-1523
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
language: python
22

33
python:
4-
- 2.5
54
- 2.6
65
- 2.7
76
- 3.1
87
- 3.2
98

109
install:
11-
- "if [[ $TRAVIS_PYTHON_VERSION == '2.5' ]]; then pip install --use-mirrors simplejson; fi"
1210
- pip install --use-mirrors cython numpy nose pytz python-dateutil
1311

1412
script:

RELEASE.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Where to get it
2525
pandas 0.9.1
2626
============
2727

28-
**Release date:** NOT YET RELEASED
28+
**Release date:** 2012-11-14
2929

3030
**New features**
3131

@@ -102,6 +102,15 @@ pandas 0.9.1
102102
e.g. DataFrame.index (#2200)
103103
- Fix conversion of mixed-type DataFrame to ndarray with dup columns (#2236)
104104
- Fix duplicate columns issue (#2218, #2219)
105+
- Fix SparseSeries.__pow__ issue with NA input (#2220)
106+
- Fix icol with integer sequence failure (#2228)
107+
- Fixed resampling tz-aware time series issue (#2245)
108+
- SparseDataFrame.icol was not returning SparseSeries (#2227, #2229)
109+
- Enable ExcelWriter to handle PeriodIndex (#2240)
110+
- Fix issue constructing DataFrame from empty Series with name (#2234)
111+
- Use console-width detection in interactive sessions only (#1610)
112+
- Fix parallel_coordinates legend bug with mpl 1.2.0 (#2237)
113+
- Make tz_localize work in corner case of empty Series (#2248)
105114
106115
pandas 0.9.0
107116
============

doc/source/v0.9.1.txt

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _whatsnew_0901:
22

3-
v0.9.1 (November 8, 2012)
4-
-------------------------
3+
v0.9.1 (November 14, 2012)
4+
--------------------------
55

66
This is a bugfix release from 0.9.0 and includes several new features and
77
enhancements along with a large number of bug fixes. The new features include
@@ -42,14 +42,44 @@ New features
4242
- DataFrame has new `where` and `mask` methods to select values according to a
4343
given boolean mask (GH2109_, GH2151_)
4444

45-
.. ipython:: python
45+
DataFrame currently supports slicing via a boolean vector the same length as the DataFrame (inside the `[]`).
46+
The returned DataFrame has the same number of columns as the original, but is sliced on its index.
47+
48+
.. ipython:: python
49+
50+
df = DataFrame(np.random.randn(5, 3), columns = ['A','B','C'])
51+
52+
df
53+
54+
df[df['A'] > 0]
55+
56+
If a DataFrame is sliced with a DataFrame based boolean condition (with the same size as the original DataFrame),
57+
then a DataFrame the same size (index and columns) as the original is returned, with
58+
elements that do not meet the boolean condition as `NaN`. This is accomplished via
59+
the new method `DataFrame.where`. In addition, `where` takes an optional `other` argument for replacement.
60+
61+
.. ipython:: python
62+
63+
df[df>0]
64+
65+
df.where(df>0)
66+
67+
df.where(df>0,-df)
68+
69+
Furthermore, `where` now aligns the input boolean condition (ndarray or DataFrame), such that partial selection
70+
with setting is possible. This is analagous to partial setting via `.ix` (but on the contents rather than the axis labels)
71+
72+
.. ipython:: python
4673

47-
df = DataFrame(np.random.randn(5, 3))
74+
df2 = df.copy()
75+
df2[ df2[1:4] > 0 ] = 3
76+
df2
4877

49-
df.where(df > 0, -df)
78+
`DataFrame.mask` is the inverse boolean operation of `where`.
5079

51-
df.mask(df < 0)
80+
.. ipython:: python
5281

82+
df.mask(df<=0)
5383

5484
- Enable referencing of Excel columns by their column names (GH1936_)
5585

pandas/core/common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,14 @@ def _concat_compat(to_concat, axis=0):
10731073
else:
10741074
return np.concatenate(to_concat, axis=axis)
10751075

1076+
def in_interactive_session():
1077+
""" check if we're running in an interactive shell
1078+
1079+
returns True if running under python/ipython interactive shell
1080+
"""
1081+
import __main__ as main
1082+
return not hasattr(main, '__file__')
1083+
10761084
# Unicode consolidation
10771085
# ---------------------
10781086
#

pandas/core/frame.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class DataFrame(NDFrame):
321321
_auto_consolidate = True
322322
_verbose_info = True
323323
_het_axis = 1
324+
_col_klass = Series
324325

325326
_AXIS_NUMBERS = {
326327
'index': 0,
@@ -581,13 +582,15 @@ def _need_info_repr_(self):
581582
else:
582583
# save us
583584
if (len(self.index) > max_rows or
584-
len(self.columns) > terminal_width // 2):
585+
(com.in_interactive_session() and
586+
len(self.columns) > terminal_width // 2)):
585587
return True
586588
else:
587589
buf = StringIO()
588590
self.to_string(buf=buf)
589591
value = buf.getvalue()
590-
if max([len(l) for l in value.split('\n')]) > terminal_width:
592+
if (max([len(l) for l in value.split('\n')]) > terminal_width and
593+
com.in_interactive_session()):
591594
return True
592595
else:
593596
return False
@@ -1179,8 +1182,12 @@ def _helper_csvexcel(self, writer, na_rep=None, cols=None,
11791182
encoded_cols = list(cols)
11801183
writer.writerow(encoded_cols)
11811184

1182-
nlevels = getattr(self.index, 'nlevels', 1)
1183-
for j, idx in enumerate(self.index):
1185+
data_index = self.index
1186+
if isinstance(self.index, PeriodIndex):
1187+
data_index = self.index.to_timestamp()
1188+
1189+
nlevels = getattr(data_index, 'nlevels', 1)
1190+
for j, idx in enumerate(data_index):
11841191
row_fields = []
11851192
if index:
11861193
if nlevels == 1:
@@ -1726,10 +1733,22 @@ def icol(self, i):
17261733
else:
17271734
label = self.columns[i]
17281735
if isinstance(label, Index):
1729-
return self.reindex(columns=label)
1736+
if self.columns.inferred_type == 'integer':
1737+
# XXX re: #2228
1738+
return self.reindex(columns=label)
1739+
else:
1740+
return self.ix[:, i]
17301741

17311742
values = self._data.iget(i)
1732-
return Series.from_array(values, index=self.index, name=label)
1743+
if hasattr(self,'default_fill_value'):
1744+
s = self._col_klass.from_array(values, index=self.index,
1745+
name=label,
1746+
fill_value= self.default_fill_value)
1747+
else:
1748+
s = self._col_klass.from_array(values, index=self.index,
1749+
name=label)
1750+
1751+
return s
17331752

17341753
def _ixs(self, i, axis=0):
17351754
if axis == 0:
@@ -5079,6 +5098,9 @@ def extract_index(data):
50795098

50805099
def _prep_ndarray(values, copy=True):
50815100
if not isinstance(values, np.ndarray):
5101+
if len(values) == 0:
5102+
return np.empty((0, 0), dtype=object)
5103+
50825104
arr = np.asarray(values)
50835105
# NumPy strings are a pain, convert to object
50845106
if issubclass(arr.dtype.type, basestring):
@@ -5091,11 +5113,7 @@ def _prep_ndarray(values, copy=True):
50915113
values = values.copy()
50925114

50935115
if values.ndim == 1:
5094-
N = values.shape[0]
5095-
if N == 0:
5096-
values = values.reshape((values.shape[0], 0))
5097-
else:
5098-
values = values.reshape((values.shape[0], 1))
5116+
values = values.reshape((values.shape[0], 1))
50995117
elif values.ndim != 2:
51005118
raise Exception('Must pass 2-d input')
51015119

pandas/core/series.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ def na_op(x, y):
110110
y = lib.list_to_object_array(y)
111111

112112
if isinstance(y, np.ndarray):
113-
result = lib.vec_compare(x, y, op)
113+
if y.dtype != np.object_:
114+
result = lib.vec_compare(x, y.astype(np.object_), op)
115+
else:
116+
result = lib.vec_compare(x, y, op)
114117
else:
115118
result = lib.scalar_compare(x, y, op)
116119
else:
@@ -2753,7 +2756,15 @@ def tz_localize(self, tz, copy=True):
27532756
-------
27542757
localized : TimeSeries
27552758
"""
2756-
new_index = self.index.tz_localize(tz)
2759+
from pandas.tseries.index import DatetimeIndex
2760+
2761+
if not isinstance(self.index, DatetimeIndex):
2762+
if len(self.index) > 0:
2763+
raise Exception('Cannot tz-localize non-time series')
2764+
2765+
new_index = DatetimeIndex([], tz=tz)
2766+
else:
2767+
new_index = self.index.tz_localize(tz)
27572768

27582769
new_values = self.values
27592770
if copy:

0 commit comments

Comments
 (0)