Skip to content

Commit e9f7619

Browse files
committed
Merge remote-tracking branch 'upstream/master' into drop_py2_ci
2 parents 7e3c14e + b2c7519 commit e9f7619

File tree

13 files changed

+94
-12
lines changed

13 files changed

+94
-12
lines changed

doc/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@
9898
if (fname == 'index.rst'
9999
and os.path.abspath(dirname) == source_path):
100100
continue
101-
elif pattern == '-api' and dirname == 'api':
101+
elif pattern == '-api' and dirname == 'reference':
102102
exclude_patterns.append(fname)
103-
elif fname != pattern:
103+
elif pattern != '-api' and fname != pattern:
104104
exclude_patterns.append(fname)
105105

106106
with open(os.path.join(source_path, 'index.rst.template')) as f:

doc/source/development/contributing.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Bug reports must:
5454
...
5555
```
5656

57-
#. Include the full version string of *pandas* and its dependencies. You can use the built in function::
57+
#. Include the full version string of *pandas* and its dependencies. You can use the built-in function::
5858

5959
>>> import pandas as pd
6060
>>> pd.show_versions()
@@ -211,7 +211,7 @@ See the full conda docs `here <http://conda.pydata.org/docs>`__.
211211
Creating a Python Environment (pip)
212212
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213213

214-
If you aren't using conda for you development environment, follow these instructions.
214+
If you aren't using conda for your development environment, follow these instructions.
215215
You'll need to have at least python3.5 installed on your system.
216216

217217
.. code-block:: none
@@ -484,7 +484,7 @@ contributing them to the project::
484484

485485
./ci/code_checks.sh
486486

487-
The script verify the linting of code files, it looks for common mistake patterns
487+
The script verifies the linting of code files, it looks for common mistake patterns
488488
(like missing spaces around sphinx directives that make the documentation not
489489
being rendered properly) and it also validates the doctests. It is possible to
490490
run the checks independently by using the parameters ``lint``, ``patterns`` and
@@ -675,7 +675,7 @@ Otherwise, you need to do it manually:
675675
676676
You'll also need to
677677

678-
1. write a new test that asserts a warning is issued when calling with the deprecated argument
678+
1. Write a new test that asserts a warning is issued when calling with the deprecated argument
679679
2. Update all of pandas existing tests and code to use the new argument
680680

681681
See :ref:`contributing.warnings` for more.

doc/source/getting_started/basics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ So, for instance, to reproduce :meth:`~DataFrame.combine_first` as above:
505505
.. ipython:: python
506506
507507
def combiner(x, y):
508-
np.where(pd.isna(x), y, x)
508+
return np.where(pd.isna(x), y, x)
509509
df1.combine(df2, combiner)
510510
511511
.. _basics.stats:

doc/source/whatsnew/v0.25.0.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ minimum versions. If installed, we now require:
5959
Other API Changes
6060
^^^^^^^^^^^^^^^^^
6161

62+
- :meth:`Timestamp.strptime` will now raise a NotImplementedError (:issue:`21257`)
63+
64+
.. _whatsnew_0250.api.other:
65+
66+
Other API Changes
67+
^^^^^^^^^^^^^^^^^
68+
6269
- :class:`DatetimeTZDtype` will now standardize pytz timezones to a common timezone instance (:issue:`24713`)
6370
- ``Timestamp`` and ``Timedelta`` scalars now implement the :meth:`to_numpy` method as aliases to :meth:`Timestamp.to_datetime64` and :meth:`Timedelta.to_timedelta64`, respectively. (:issue:`24653`)
6471
-
@@ -175,10 +182,9 @@ Missing
175182
MultiIndex
176183
^^^^^^^^^^
177184

185+
- Bug in which incorrect exception raised by :meth:`pd.Timedelta` when testing the membership of :class:`MultiIndex` (:issue:`24570`)
178186
-
179187
-
180-
-
181-
182188

183189
I/O
184190
^^^

pandas/_libs/tslibs/nattype.pyx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ class NaTType(_NaT):
374374
utctimetuple = _make_error_func('utctimetuple', datetime)
375375
timetz = _make_error_func('timetz', datetime)
376376
timetuple = _make_error_func('timetuple', datetime)
377-
strptime = _make_error_func('strptime', datetime)
378377
strftime = _make_error_func('strftime', datetime)
379378
isocalendar = _make_error_func('isocalendar', datetime)
380379
dst = _make_error_func('dst', datetime)
@@ -388,6 +387,14 @@ class NaTType(_NaT):
388387
# The remaining methods have docstrings copy/pasted from the analogous
389388
# Timestamp methods.
390389

390+
strptime = _make_error_func('strptime', # noqa:E128
391+
"""
392+
Timestamp.strptime(string, format)
393+
394+
Function is not implemented. Use pd.to_datetime().
395+
"""
396+
)
397+
391398
utcfromtimestamp = _make_error_func('utcfromtimestamp', # noqa:E128
392399
"""
393400
Timestamp.utcfromtimestamp(ts)

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,17 @@ class Timestamp(_Timestamp):
697697
"""
698698
return cls(datetime.fromtimestamp(ts))
699699

700+
# Issue 25016.
701+
@classmethod
702+
def strptime(cls, date_string, format):
703+
"""
704+
Timestamp.strptime(string, format)
705+
706+
Function is not implemented. Use pd.to_datetime().
707+
"""
708+
raise NotImplementedError("Timestamp.strptime() is not implmented."
709+
"Use to_datetime() to parse date strings.")
710+
700711
@classmethod
701712
def combine(cls, date, time):
702713
"""

pandas/core/generic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,6 @@ def _set_axis_name(self, name, axis=0, inplace=False):
13331333
cat 4
13341334
monkey 2
13351335
"""
1336-
pd.MultiIndex.from_product([["mammal"], ['dog', 'cat', 'monkey']])
13371336
axis = self._get_axis_number(axis)
13381337
idx = self._get_axis(axis).set_names(name)
13391338

pandas/core/indexes/multi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ def __contains__(self, key):
840840
try:
841841
self.get_loc(key)
842842
return True
843-
except (LookupError, TypeError):
843+
except (LookupError, TypeError, ValueError):
844844
return False
845845

846846
contains = __contains__

pandas/tests/frame/test_combine_concat.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,16 @@ def test_concat_numerical_names(self):
504504
names=[1, 2]))
505505
tm.assert_frame_equal(result, expected)
506506

507+
def test_concat_astype_dup_col(self):
508+
# gh 23049
509+
df = pd.DataFrame([{'a': 'b'}])
510+
df = pd.concat([df, df], axis=1)
511+
512+
result = df.astype('category')
513+
expected = pd.DataFrame(np.array(["b", "b"]).reshape(1, 2),
514+
columns=["a", "a"]).astype("category")
515+
tm.assert_frame_equal(result, expected)
516+
507517

508518
class TestDataFrameCombineFirst(TestData):
509519

pandas/tests/groupby/aggregate/test_aggregate.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,20 @@ def test_multi_function_flexible_mix(df):
286286
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
287287
result = grouped.aggregate(d)
288288
tm.assert_frame_equal(result, expected)
289+
290+
291+
def test_groupby_agg_coercing_bools():
292+
# issue 14873
293+
dat = pd.DataFrame(
294+
{'a': [1, 1, 2, 2], 'b': [0, 1, 2, 3], 'c': [None, None, 1, 1]})
295+
gp = dat.groupby('a')
296+
297+
index = Index([1, 2], name='a')
298+
299+
result = gp['b'].aggregate(lambda x: (x != 0).all())
300+
expected = Series([False, True], index=index, name='b')
301+
tm.assert_series_equal(result, expected)
302+
303+
result = gp['c'].aggregate(lambda x: x.isnull().all())
304+
expected = Series([True, False], index=index, name='c')
305+
tm.assert_series_equal(result, expected)

pandas/tests/groupby/test_groupby.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,3 +1698,19 @@ def test_groupby_agg_ohlc_non_first():
16981698
result = df.groupby(pd.Grouper(freq='D')).agg(['sum', 'ohlc'])
16991699

17001700
tm.assert_frame_equal(result, expected)
1701+
1702+
1703+
def test_groupby_multiindex_nat():
1704+
# GH 9236
1705+
values = [
1706+
(pd.NaT, 'a'),
1707+
(datetime(2012, 1, 2), 'a'),
1708+
(datetime(2012, 1, 2), 'b'),
1709+
(datetime(2012, 1, 3), 'a')
1710+
]
1711+
mi = pd.MultiIndex.from_tuples(values, names=['date', None])
1712+
ser = pd.Series([3, 2, 2.5, 4], index=mi)
1713+
1714+
result = ser.groupby(level=1).mean()
1715+
expected = pd.Series([3., 2.5], index=["a", "b"])
1716+
assert_series_equal(result, expected)

pandas/tests/indexing/multiindex/test_multiindex.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,11 @@ def test_multi_nan_indexing(self):
8484
name='a'),
8585
Index(['C1', 'C2', 'C3', 'C4'], name='b')])
8686
tm.assert_frame_equal(result, expected)
87+
88+
def test_contains(self):
89+
# GH 24570
90+
tx = pd.timedelta_range('09:30:00', '16:00:00', freq='30 min')
91+
idx = MultiIndex.from_arrays([tx, np.arange(len(tx))])
92+
assert tx[0] in idx
93+
assert 'element_not_exit' not in idx
94+
assert '0 day 09:30:00' in idx

pandas/tests/scalar/timestamp/test_timestamp.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ def test_constructor_invalid_tz(self):
355355
# interpreted as a `freq`
356356
Timestamp('2012-01-01', 'US/Pacific')
357357

358+
def test_constructor_strptime(self):
359+
# GH25016
360+
# Test support for Timestamp.strptime
361+
fmt = '%Y%m%d-%H%M%S-%f%z'
362+
ts = '20190129-235348-000001+0000'
363+
with pytest.raises(NotImplementedError):
364+
Timestamp.strptime(ts, fmt)
365+
358366
def test_constructor_tz_or_tzinfo(self):
359367
# GH#17943, GH#17690, GH#5168
360368
stamps = [Timestamp(year=2017, month=10, day=22, tz='UTC'),

0 commit comments

Comments
 (0)