Skip to content

Commit ac0003f

Browse files
author
dcreekp
committed
Merge branch 'master' of github.com:pandas-dev/pandas
2 parents e2261f9 + 99df7da commit ac0003f

File tree

140 files changed

+3811
-2904
lines changed

Some content is hidden

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

140 files changed

+3811
-2904
lines changed

.pep8speaks.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pycodestyle:
1313
- W503, # line break before binary operator
1414
- W504, # line break after binary operator
1515
- E402, # module level import not at top of file
16-
- E722, # do not use bare except
1716
- E731, # do not assign a lambda expression, use a def
1817
- C406, # Unnecessary list literal - rewrite as a dict literal.
1918
- C408, # Unnecessary dict call - rewrite as a literal.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build: clean_pyc
1313
python setup.py build_ext --inplace
1414

1515
lint-diff:
16-
git diff master --name-only -- "*.py" | grep -E "pandas|scripts" | xargs flake8
16+
git diff upstream/master --name-only -- "*.py" | xargs flake8
1717

1818
develop: build
1919
-python setup.py develop

asv_bench/benchmarks/timeseries.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import timedelta
22

3+
import dateutil
34
import numpy as np
45
from pandas import to_datetime, date_range, Series, DataFrame, period_range
56
from pandas.tseries.frequencies import infer_freq
@@ -57,7 +58,10 @@ def time_to_pydatetime(self, index_type):
5758

5859
class TzLocalize(object):
5960

60-
def setup(self):
61+
params = [None, 'US/Eastern', 'UTC', dateutil.tz.tzutc()]
62+
param_names = 'tz'
63+
64+
def setup(self, tz):
6165
dst_rng = date_range(start='10/29/2000 1:00:00',
6266
end='10/29/2000 1:59:59', freq='S')
6367
self.index = date_range(start='10/29/2000',
@@ -68,8 +72,8 @@ def setup(self):
6872
end='10/29/2000 3:00:00',
6973
freq='S'))
7074

71-
def time_infer_dst(self):
72-
self.index.tz_localize('US/Eastern', ambiguous='infer')
75+
def time_infer_dst(self, tz):
76+
self.index.tz_localize(tz, ambiguous='infer')
7377

7478

7579
class ResetIndex(object):
@@ -377,15 +381,35 @@ def time_dup_string_tzoffset_dates(self, cache):
377381

378382
class DatetimeAccessor(object):
379383

380-
def setup(self):
384+
params = [None, 'US/Eastern', 'UTC', dateutil.tz.tzutc()]
385+
param_names = 'tz'
386+
387+
def setup(self, tz):
381388
N = 100000
382-
self.series = Series(date_range(start='1/1/2000', periods=N, freq='T'))
389+
self.series = Series(
390+
date_range(start='1/1/2000', periods=N, freq='T', tz=tz)
391+
)
383392

384-
def time_dt_accessor(self):
393+
def time_dt_accessor(self, tz):
385394
self.series.dt
386395

387-
def time_dt_accessor_normalize(self):
396+
def time_dt_accessor_normalize(self, tz):
388397
self.series.dt.normalize()
389398

399+
def time_dt_accessor_month_name(self, tz):
400+
self.series.dt.month_name()
401+
402+
def time_dt_accessor_day_name(self, tz):
403+
self.series.dt.day_name()
404+
405+
def time_dt_accessor_time(self, tz):
406+
self.series.dt.time
407+
408+
def time_dt_accessor_date(self, tz):
409+
self.series.dt.date
410+
411+
def time_dt_accessor_year(self, tz):
412+
self.series.dt.year
413+
390414

391415
from .pandas_vb_common import setup # noqa: F401

asv_bench/benchmarks/timestamp.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from pandas import Timestamp
44
import pytz
5+
import dateutil
56

67

78
class TimestampConstruction(object):
@@ -29,7 +30,8 @@ def time_fromtimestamp(self):
2930

3031

3132
class TimestampProperties(object):
32-
_tzs = [None, pytz.timezone('Europe/Amsterdam')]
33+
_tzs = [None, pytz.timezone('Europe/Amsterdam'), pytz.UTC,
34+
dateutil.tz.tzutc()]
3335
_freqs = [None, 'B']
3436
params = [_tzs, _freqs]
3537
param_names = ['tz', 'freq']
@@ -87,7 +89,8 @@ def time_microsecond(self, tz, freq):
8789

8890

8991
class TimestampOps(object):
90-
params = [None, 'US/Eastern']
92+
params = [None, 'US/Eastern', pytz.UTC,
93+
dateutil.tz.tzutc()]
9194
param_names = ['tz']
9295

9396
def setup(self, tz):
@@ -102,6 +105,17 @@ def time_replace_None(self, tz):
102105
def time_to_pydatetime(self, tz):
103106
self.ts.to_pydatetime()
104107

108+
def time_normalize(self, tz):
109+
self.ts.normalize()
110+
111+
def time_tz_convert(self, tz):
112+
if self.ts.tz is not None:
113+
self.ts.tz_convert(tz)
114+
115+
def time_tz_localize(self, tz):
116+
if self.ts.tz is None:
117+
self.ts.tz_localize(tz)
118+
105119

106120
class TimestampAcrossDst(object):
107121
def setup(self):

ci/deps/azure-27-compat.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
- pytz=2013b
1717
- scipy=0.18.1
1818
- sqlalchemy=0.7.8
19-
- xlrd=0.9.2
19+
- xlrd=1.0.0
2020
- xlsxwriter=0.5.2
2121
- xlwt=0.7.5
2222
# universal

ci/deps/travis-27-locale.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
- pytz=2013b
1717
- scipy
1818
- sqlalchemy=0.8.1
19-
- xlrd=0.9.2
19+
- xlrd=1.0.0
2020
- xlsxwriter=0.5.2
2121
- xlwt=0.7.5
2222
# universal

ci/deps/travis-27.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies:
3535
- scipy
3636
- sqlalchemy=0.9.6
3737
- xarray=0.9.6
38-
- xlrd=0.9.2
38+
- xlrd=1.0.0
3939
- xlsxwriter=0.5.2
4040
- xlwt=0.7.5
4141
# universal

ci/deps/travis-36-doc.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: pandas
22
channels:
33
- defaults
44
- conda-forge
5-
- r
65
dependencies:
76
- beautifulsoup4
87
- bottleneck
@@ -31,14 +30,11 @@ dependencies:
3130
- python-snappy
3231
- python=3.6*
3332
- pytz
34-
- r
35-
- rpy2
3633
- scipy
3734
- seaborn
3835
- sphinx
3936
- sqlalchemy
4037
- statsmodels
41-
- tzlocal
4238
- xarray
4339
- xlrd
4440
- xlsxwriter

doc/source/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ def linkcode_resolve(domain, info):
586586
for part in fullname.split('.'):
587587
try:
588588
obj = getattr(obj, part)
589-
except:
589+
except AttributeError:
590590
return None
591591

592592
try:
@@ -595,14 +595,14 @@ def linkcode_resolve(domain, info):
595595
fn = inspect.getsourcefile(inspect.unwrap(obj))
596596
else:
597597
fn = inspect.getsourcefile(obj)
598-
except:
598+
except TypeError:
599599
fn = None
600600
if not fn:
601601
return None
602602

603603
try:
604604
source, lineno = inspect.getsourcelines(obj)
605-
except:
605+
except OSError:
606606
lineno = None
607607

608608
if lineno:

doc/source/contributing.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ the `flake8 <https://pypi.org/project/flake8>`_ tool
575575
and report any stylistic errors in your code. Therefore, it is helpful before
576576
submitting code to run the check yourself on the diff::
577577

578-
git diff master -u -- "*.py" | flake8 --diff
578+
git diff upstream/master -u -- "*.py" | flake8 --diff
579579

580580
This command will catch any stylistic errors in your changes specifically, but
581581
be beware it may not catch all of them. For example, if you delete the only
@@ -584,21 +584,21 @@ unused function. However, style-checking the diff will not catch this because
584584
the actual import is not part of the diff. Thus, for completeness, you should
585585
run this command, though it will take longer::
586586

587-
git diff master --name-only -- "*.py" | grep "pandas/" | xargs -r flake8
587+
git diff upstream/master --name-only -- "*.py" | xargs -r flake8
588588

589589
Note that on OSX, the ``-r`` flag is not available, so you have to omit it and
590590
run this slightly modified command::
591591

592-
git diff master --name-only -- "*.py" | grep "pandas/" | xargs flake8
592+
git diff upstream/master --name-only -- "*.py" | xargs flake8
593593

594-
Windows does not support the ``grep`` and ``xargs`` commands (unless installed
595-
for example via the `MinGW <http://www.mingw.org/>`__ toolchain), but one can
596-
imitate the behaviour as follows::
594+
Windows does not support the ``xargs`` command (unless installed for example
595+
via the `MinGW <http://www.mingw.org/>`__ toolchain), but one can imitate the
596+
behaviour as follows::
597597

598-
for /f %i in ('git diff upstream/master --name-only ^| findstr pandas/') do flake8 %i
598+
for /f %i in ('git diff upstream/master --name-only -- "*.py"') do flake8 %i
599599

600-
This will also get all the files being changed by the PR (and within the
601-
``pandas/`` folder), and run ``flake8`` on them one after the other.
600+
This will get all the files being changed by the PR (and ending with ``.py``),
601+
and run ``flake8`` on them, one after the other.
602602

603603
.. _contributing.import-formatting:
604604

doc/source/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Optional Dependencies
269269
* `matplotlib <http://matplotlib.org/>`__: for plotting, Version 2.0.0 or higher.
270270
* For Excel I/O:
271271

272-
* `xlrd/xlwt <http://www.python-excel.org/>`__: Excel reading (xlrd) and writing (xlwt)
272+
* `xlrd/xlwt <http://www.python-excel.org/>`__: Excel reading (xlrd), version 1.0.0 or higher required, and writing (xlwt)
273273
* `openpyxl <https://openpyxl.readthedocs.io/en/stable/>`__: openpyxl version 2.4.0
274274
for writing .xlsx files (xlrd >= 0.9.0)
275275
* `XlsxWriter <https://pypi.org/project/XlsxWriter>`__: Alternative Excel writer

doc/source/r_interface.rst

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,28 @@ See also the documentation of the `rpy2 <http://rpy2.bitbucket.org/>`__ project:
3333

3434
In the remainder of this page, a few examples of explicit conversion is given. The pandas conversion of rpy2 needs first to be activated:
3535

36-
.. ipython:: python
36+
.. code-block:: python
3737
38-
from rpy2.robjects import r, pandas2ri
39-
pandas2ri.activate()
38+
>>> from rpy2.robjects import pandas2ri # doctest: +SKIP
39+
>>> pandas2ri.activate() # doctest: +SKIP
4040
4141
Transferring R data sets into Python
4242
------------------------------------
4343

4444
Once the pandas conversion is activated (``pandas2ri.activate()``), many conversions
4545
of R to pandas objects will be done automatically. For example, to obtain the 'iris' dataset as a pandas DataFrame:
4646

47-
.. ipython:: python
47+
.. code-block:: python
4848
49-
r.data('iris')
50-
r['iris'].head()
49+
>>> from rpy2.robjects import r # doctest: +SKIP
50+
>>> r.data('iris') # doctest: +SKIP
51+
>>> r['iris'].head() # doctest: +SKIP
52+
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
53+
0 5.1 3.5 1.4 0.2 setosa
54+
1 4.9 3.0 1.4 0.2 setosa
55+
2 4.7 3.2 1.3 0.2 setosa
56+
3 4.6 3.1 1.5 0.2 setosa
57+
4 5.0 3.6 1.4 0.2 setosa
5158
5259
If the pandas conversion was not activated, the above could also be accomplished
5360
by explicitly converting it with the ``pandas2ri.ri2py`` function
@@ -59,13 +66,19 @@ Converting DataFrames into R objects
5966
The ``pandas2ri.py2ri`` function support the reverse operation to convert
6067
DataFrames into the equivalent R object (that is, **data.frame**):
6168

62-
.. ipython:: python
69+
.. code-block:: python
70+
71+
>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]},
72+
... index=["one", "two", "three"]) # doctest: +SKIP
73+
>>> r_dataframe = pandas2ri.py2ri(df) # doctest: +SKIP
74+
>>> print(type(r_dataframe)) # doctest: +SKIP
75+
<class 'rpy2.robjects.vectors.DataFrame'>
76+
>>> print(r_dataframe) # doctest: +SKIP
77+
A B C
78+
one 1 4 7
79+
two 2 5 8
80+
three 3 6 9
6381
64-
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]},
65-
index=["one", "two", "three"])
66-
r_dataframe = pandas2ri.py2ri(df)
67-
print(type(r_dataframe))
68-
print(r_dataframe)
6982
7083
The DataFrame's index is stored as the ``rownames`` attribute of the
7184
data.frame instance.

0 commit comments

Comments
 (0)