Skip to content

Commit 1b7261c

Browse files
Merge remote-tracking branch 'upstream/master' into typing
2 parents c13af90 + 505b6e7 commit 1b7261c

File tree

216 files changed

+406
-481
lines changed

Some content is hidden

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

216 files changed

+406
-481
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
custom: https://pandas.pydata.org/donate.html
2+
github: [numfocus]
23
tidelift: pypi/pandas

asv_bench/benchmarks/gil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def wrapper(fname):
3737
return wrapper
3838

3939

40-
from .pandas_vb_common import BaseIO # noqa: E402 isort:skip
40+
from .pandas_vb_common import BaseIO # isort:skip
4141

4242

4343
class ParallelGroupbyMethods:

asv_bench/benchmarks/offset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pandas as pd
44

55
try:
6-
import pandas.tseries.holiday # noqa
6+
import pandas.tseries.holiday
77
except ImportError:
88
pass
99

doc/source/whatsnew/v1.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ Datetimelike
314314
- Bug in :func:`pandas.core.groupby.generic.SeriesGroupBy.apply` raising ``ValueError`` when a column in the original DataFrame is a datetime and the column labels are not standard integers (:issue:`28247`)
315315
- Bug in :func:`pandas._config.localization.get_locales` where the ``locales -a`` encodes the locales list as windows-1252 (:issue:`23638`, :issue:`24760`, :issue:`27368`)
316316
- Bug in :meth:`Series.var` failing to raise ``TypeError`` when called with ``timedelta64[ns]`` dtype (:issue:`28289`)
317-
-
317+
- Bug in :meth:`DatetimeIndex.strftime` and :meth:`Series.dt.strftime` where ``NaT`` was converted to the string ``'NaT'`` instead of ``np.nan`` (:issue:`29578`)
318318

319319
Timedelta
320320
^^^^^^^^^

pandas/_libs/parsers.pyx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -843,11 +843,6 @@ cdef class TextReader:
843843

844844
passed_count = len(header[0])
845845

846-
# if passed_count > field_count:
847-
# raise ParserError('Column names have %d fields, '
848-
# 'data has %d fields'
849-
# % (passed_count, field_count))
850-
851846
if (self.has_usecols and self.allow_leading_cols and
852847
not callable(self.usecols)):
853848
nuse = len(self.usecols)

pandas/_libs/reduction.pyx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ cdef class Reducer:
8282
else:
8383

8484
# we passed a series-like
85-
if hasattr(dummy, 'values'):
86-
87-
typ = type(dummy)
88-
index = getattr(dummy, 'index', None)
89-
dummy = dummy.values
85+
typ = type(dummy)
86+
index = dummy.index
87+
dummy = dummy.values
9088

9189
if dummy.dtype != self.arr.dtype:
9290
raise ValueError('Dummy array must be same dtype')
@@ -99,10 +97,10 @@ cdef class Reducer:
9997
cdef:
10098
char* dummy_buf
10199
ndarray arr, result, chunk
102-
Py_ssize_t i, incr
100+
Py_ssize_t i
103101
flatiter it
104102
bint has_labels
105-
object res, name, labels, index
103+
object res, name, labels
106104
object cached_typ = None
107105

108106
arr = self.arr
@@ -112,7 +110,6 @@ cdef class Reducer:
112110
labels = self.labels
113111
has_labels = labels is not None
114112
has_index = self.index is not None
115-
incr = self.increment
116113

117114
result = np.empty(self.nresults, dtype='O')
118115
it = <flatiter>PyArray_IterNew(result)
@@ -193,10 +190,10 @@ cdef class _BaseGrouper:
193190
return values, index
194191

195192
cdef inline _update_cached_objs(self, object cached_typ, object cached_ityp,
196-
Slider islider, Slider vslider, object name):
193+
Slider islider, Slider vslider):
197194
if cached_typ is None:
198195
cached_ityp = self.ityp(islider.buf)
199-
cached_typ = self.typ(vslider.buf, index=cached_ityp, name=name)
196+
cached_typ = self.typ(vslider.buf, index=cached_ityp, name=self.name)
200197
else:
201198
# See the comment in indexes/base.py about _index_data.
202199
# We need this for EA-backed indexes that have a reference
@@ -205,7 +202,7 @@ cdef class _BaseGrouper:
205202
cached_ityp._engine.clear_mapping()
206203
object.__setattr__(cached_typ._data._block, 'values', vslider.buf)
207204
object.__setattr__(cached_typ, '_index', cached_ityp)
208-
object.__setattr__(cached_typ, 'name', name)
205+
object.__setattr__(cached_typ, 'name', self.name)
209206

210207
return cached_typ, cached_ityp
211208

@@ -224,6 +221,7 @@ cdef class SeriesBinGrouper(_BaseGrouper):
224221
def __init__(self, object series, object f, object bins, object dummy):
225222

226223
assert dummy is not None # always obj[:0]
224+
assert len(bins) > 0 # otherwise we get IndexError in get_result
227225

228226
self.bins = bins
229227
self.f = f
@@ -254,7 +252,7 @@ cdef class SeriesBinGrouper(_BaseGrouper):
254252
object res
255253
bint initialized = 0
256254
Slider vslider, islider
257-
object name, cached_typ = None, cached_ityp = None
255+
object cached_typ = None, cached_ityp = None
258256

259257
counts = np.zeros(self.ngroups, dtype=np.int64)
260258

@@ -268,7 +266,6 @@ cdef class SeriesBinGrouper(_BaseGrouper):
268266

269267
group_size = 0
270268
n = len(self.arr)
271-
name = self.name
272269

273270
vslider = Slider(self.arr, self.dummy_arr)
274271
islider = Slider(self.index, self.dummy_index)
@@ -283,7 +280,7 @@ cdef class SeriesBinGrouper(_BaseGrouper):
283280
vslider.set_length(group_size)
284281

285282
cached_typ, cached_ityp = self._update_cached_objs(
286-
cached_typ, cached_ityp, islider, vslider, name)
283+
cached_typ, cached_ityp, islider, vslider)
287284

288285
cached_ityp._engine.clear_mapping()
289286
res = self.f(cached_typ)
@@ -356,13 +353,12 @@ cdef class SeriesGrouper(_BaseGrouper):
356353
object res
357354
bint initialized = 0
358355
Slider vslider, islider
359-
object name, cached_typ = None, cached_ityp = None
356+
object cached_typ = None, cached_ityp = None
360357

361358
labels = self.labels
362359
counts = np.zeros(self.ngroups, dtype=np.int64)
363360
group_size = 0
364361
n = len(self.arr)
365-
name = self.name
366362

367363
vslider = Slider(self.arr, self.dummy_arr)
368364
islider = Slider(self.index, self.dummy_index)
@@ -386,7 +382,7 @@ cdef class SeriesGrouper(_BaseGrouper):
386382
vslider.set_length(group_size)
387383

388384
cached_typ, cached_ityp = self._update_cached_objs(
389-
cached_typ, cached_ityp, islider, vslider, name)
385+
cached_typ, cached_ityp, islider, vslider)
390386

391387
cached_ityp._engine.clear_mapping()
392388
res = self.f(cached_typ)

pandas/_libs/src/parser/tokenizer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ typedef struct parser_t {
162162
int64_t skip_footer;
163163
// pick one, depending on whether the converter requires GIL
164164
double (*double_converter_nogil)(const char *, char **,
165-
char, char, char, int);
165+
char, char, char, int, int *, int *);
166166
double (*double_converter_withgil)(const char *, char **,
167-
char, char, char, int);
167+
char, char, char, int, int *, int *);
168168

169169
// error handling
170170
char *warn_msg;

pandas/_libs/tslibs/c_timestamp.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ cdef class _Timestamp(datetime):
201201
"""
202202
return np.datetime64(self.value, 'ns')
203203

204-
def to_numpy(self, dtype=None, copy=False):
204+
def to_numpy(self, dtype=None, copy=False) -> np.datetime64:
205205
"""
206206
Convert the Timestamp to a NumPy datetime64.
207207

@@ -369,18 +369,18 @@ cdef class _Timestamp(datetime):
369369
return out[0]
370370

371371
@property
372-
def _repr_base(self):
372+
def _repr_base(self) -> str:
373373
return '{date} {time}'.format(date=self._date_repr,
374374
time=self._time_repr)
375375

376376
@property
377-
def _date_repr(self):
377+
def _date_repr(self) -> str:
378378
# Ideal here would be self.strftime("%Y-%m-%d"), but
379379
# the datetime strftime() methods require year >= 1900
380380
return '%d-%.2d-%.2d' % (self.year, self.month, self.day)
381381

382382
@property
383-
def _time_repr(self):
383+
def _time_repr(self) -> str:
384384
result = '%.2d:%.2d:%.2d' % (self.hour, self.minute, self.second)
385385

386386
if self.nanosecond != 0:
@@ -391,7 +391,7 @@ cdef class _Timestamp(datetime):
391391
return result
392392

393393
@property
394-
def _short_repr(self):
394+
def _short_repr(self) -> str:
395395
# format a Timestamp with only _date_repr if possible
396396
# otherwise _repr_base
397397
if (self.hour == 0 and
@@ -403,7 +403,7 @@ cdef class _Timestamp(datetime):
403403
return self._repr_base
404404

405405
@property
406-
def asm8(self):
406+
def asm8(self) -> np.datetime64:
407407
"""
408408
Return numpy datetime64 format in nanoseconds.
409409
"""

pandas/_libs/tslibs/nattype.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,16 @@ cdef class _NaT(datetime):
230230
return NotImplemented
231231

232232
@property
233-
def asm8(self):
233+
def asm8(self) -> np.datetime64:
234234
return np.datetime64(NPY_NAT, 'ns')
235235

236-
def to_datetime64(self):
236+
def to_datetime64(self) -> np.datetime64:
237237
"""
238238
Return a numpy.datetime64 object with 'ns' precision.
239239
"""
240240
return np.datetime64('NaT', 'ns')
241241

242-
def to_numpy(self, dtype=None, copy=False):
242+
def to_numpy(self, dtype=None, copy=False) -> np.datetime64:
243243
"""
244244
Convert the Timestamp to a NumPy datetime64.
245245

@@ -265,7 +265,7 @@ cdef class _NaT(datetime):
265265
def __str__(self) -> str:
266266
return 'NaT'
267267

268-
def isoformat(self, sep='T'):
268+
def isoformat(self, sep='T') -> str:
269269
# This allows Timestamp(ts.isoformat()) to always correctly roundtrip.
270270
return 'NaT'
271271

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -841,15 +841,15 @@ cdef class _Timedelta(timedelta):
841841
"""
842842
return timedelta(microseconds=int(self.value) / 1000)
843843

844-
def to_timedelta64(self):
844+
def to_timedelta64(self) -> np.timedelta64:
845845
"""
846846
Return a numpy.timedelta64 object with 'ns' precision.
847847
"""
848848
return np.timedelta64(self.value, 'ns')
849849

850-
def to_numpy(self, dtype=None, copy=False):
850+
def to_numpy(self, dtype=None, copy=False) -> np.timedelta64:
851851
"""
852-
Convert the Timestamp to a NumPy timedelta64.
852+
Convert the Timedelta to a NumPy timedelta64.
853853

854854
.. versionadded:: 0.25.0
855855

@@ -920,7 +920,7 @@ cdef class _Timedelta(timedelta):
920920
return self.value
921921

922922
@property
923-
def asm8(self):
923+
def asm8(self) -> np.timedelta64:
924924
"""
925925
Return a numpy timedelta64 array scalar view.
926926

@@ -955,7 +955,7 @@ cdef class _Timedelta(timedelta):
955955
return np.int64(self.value).view('m8[ns]')
956956

957957
@property
958-
def resolution_string(self):
958+
def resolution_string(self) -> str:
959959
"""
960960
Return a string representing the lowest timedelta resolution.
961961

@@ -1095,7 +1095,7 @@ cdef class _Timedelta(timedelta):
10951095
self._ensure_components()
10961096
return self._ns
10971097

1098-
def _repr_base(self, format=None):
1098+
def _repr_base(self, format=None) -> str:
10991099
"""
11001100

11011101
Parameters
@@ -1148,10 +1148,10 @@ cdef class _Timedelta(timedelta):
11481148
def __str__(self) -> str:
11491149
return self._repr_base(format='long')
11501150

1151-
def __bool__(self):
1151+
def __bool__(self) -> bool:
11521152
return self.value != 0
11531153

1154-
def isoformat(self):
1154+
def isoformat(self) -> str:
11551155
"""
11561156
Format Timedelta as ISO 8601 Duration like
11571157
``P[n]Y[n]M[n]DT[n]H[n]M[n]S``, where the ``[n]`` s are replaced by the

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ from pandas._libs.tslibs.tzconversion import (
3636
# Constants
3737
_zero_time = datetime_time(0, 0)
3838
_no_input = object()
39-
PY36 = sys.version_info >= (3, 6)
4039

4140
# ----------------------------------------------------------------------
4241

@@ -982,9 +981,8 @@ default 'raise'
982981
else:
983982
kwargs = {'year': dts.year, 'month': dts.month, 'day': dts.day,
984983
'hour': dts.hour, 'minute': dts.min, 'second': dts.sec,
985-
'microsecond': dts.us, 'tzinfo': _tzinfo}
986-
if PY36:
987-
kwargs['fold'] = fold
984+
'microsecond': dts.us, 'tzinfo': _tzinfo,
985+
'fold': fold}
988986
ts_input = datetime(**kwargs)
989987

990988
ts = convert_datetime_to_tsobject(ts_input, _tzinfo)

pandas/compat/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import sys
1313
import warnings
1414

15-
PY36 = sys.version_info >= (3, 6)
1615
PY37 = sys.version_info >= (3, 7)
1716
PY38 = sys.version_info >= (3, 8)
1817
PYPY = platform.python_implementation() == "PyPy"

0 commit comments

Comments
 (0)