Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into Rt05
Browse files Browse the repository at this point in the history
* upstream/master:
  DOC: Fix validation type error SA05 (pandas-dev#25208)
  REF: Add more pytest idiom to test_holiday.py (pandas-dev#25204)
  DOC/CLN: Fix errors in Series docstrings (pandas-dev#24945)
  TST: follow-up to Test nested pandas array pandas-dev#24993 (pandas-dev#25155)
  modernize compat imports (pandas-dev#25192)
  fix MacPython pandas-wheels failure (pandas-dev#25186)
  BUG: DataFrame.merge(suffixes=) does not respect None (pandas-dev#24819)
  DEPR: remove PanelGroupBy, disable DataFrame.to_panel (pandas-dev#25047)
  DOC: update docstring for series.nunique (pandas-dev#25116)
  CLN: Use ABCs in set_index (pandas-dev#25128)
  BLD: pin cython language level to '2' (pandas-dev#25145)
  DOC: Updates to Timestamp document (pandas-dev#25163)
  STY: use pytest.raises context manager (indexes/multi) (pandas-dev#25175)
  Fixed tuple to List Conversion in Dataframe class (pandas-dev#25089)
  • Loading branch information
thoo committed Feb 7, 2019
2 parents 163e9e3 + 683c7b5 commit b55b270
Show file tree
Hide file tree
Showing 92 changed files with 1,621 additions and 1,917 deletions.
4 changes: 2 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ fi
### DOCSTRINGS ###
if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then

MSG='Validate docstrings (GL06, GL07, GL09, SS04, SS05, PR03, PR05, EX04, RT04, RT05)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=azure --errors=GL06,GL07,GL09,SS04,SS05,PR03,PR05,EX04,RT04,RT05
MSG='Validate docstrings (GL06, GL07, GL09, SS04, SS05, PR03, PR05, EX04, RT04, RT05, SA05)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=azure --errors=GL06,GL07,GL09,SS04,SS05,PR03,PR05,EX04,RT04,RT05,SA05
RET=$(($RET + $?)) ; echo $MSG "DONE"

fi
Expand Down
4 changes: 3 additions & 1 deletion doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Fixed Regressions

- Fixed regression in :meth:`DataFrame.all` and :meth:`DataFrame.any` where ``bool_only=True`` was ignored (:issue:`25101`)

- Fixed issue in ``DataFrame`` construction with passing a mixed list of mixed types could segfault. (:issue:`25075`)

.. _whatsnew_0242.enhancements:

Enhancements
Expand Down Expand Up @@ -94,4 +96,4 @@ Bug Fixes
Contributors
~~~~~~~~~~~~

.. contributors:: v0.24.1..v0.24.2
.. contributors:: v0.24.1..v0.24.2
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Deprecations

Removal of prior version deprecations/changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- Removed (parts of) :class:`Panel` (:issue:`25047`)
-
-
-
Expand Down Expand Up @@ -181,6 +181,7 @@ Groupby/Resample/Rolling
Reshaping
^^^^^^^^^

- Bug in :func:`pandas.merge` adds a string of ``None`` if ``None`` is assigned in suffixes instead of remain the column name as-is (:issue:`24782`).
- Bug in :func:`merge` when merging by index name would sometimes result in an incorrectly numbered index (:issue:`24212`)
- :func:`to_records` now accepts dtypes to its `column_dtypes` parameter (:issue:`24895`)
-
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2277,7 +2277,7 @@ def to_object_array(rows: object, int min_width=0):
result = np.empty((n, k), dtype=object)

for i in range(n):
row = <list>input_rows[i]
row = list(input_rows[i])

for j in range(len(row)):
result[i, j] = row[j]
Expand Down
45 changes: 45 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ cdef class _Timestamp(datetime):

@property
def asm8(self):
"""
Return numpy datetime64 format in nanoseconds.
"""
return np.datetime64(self.value, 'ns')

@property
Expand Down Expand Up @@ -570,15 +573,18 @@ class Timestamp(_Timestamp):
Using the primary calling convention:
This converts a datetime-like string
>>> pd.Timestamp('2017-01-01T12')
Timestamp('2017-01-01 12:00:00')
This converts a float representing a Unix epoch in units of seconds
>>> pd.Timestamp(1513393355.5, unit='s')
Timestamp('2017-12-16 03:02:35.500000')
This converts an int representing a Unix-epoch in units of seconds
and for a particular timezone
>>> pd.Timestamp(1513393355, unit='s', tz='US/Pacific')
Timestamp('2017-12-15 19:02:35-0800', tz='US/Pacific')
Expand Down Expand Up @@ -934,6 +940,9 @@ class Timestamp(_Timestamp):

@property
def dayofweek(self):
"""
Return day of whe week.
"""
return self.weekday()

def day_name(self, locale=None):
Expand Down Expand Up @@ -983,72 +992,108 @@ class Timestamp(_Timestamp):

@property
def dayofyear(self):
"""
Return the day of the year.
"""
return ccalendar.get_day_of_year(self.year, self.month, self.day)

@property
def week(self):
"""
Return the week number of the year.
"""
return ccalendar.get_week_of_year(self.year, self.month, self.day)

weekofyear = week

@property
def quarter(self):
"""
Return the quarter of the year.
"""
return ((self.month - 1) // 3) + 1

@property
def days_in_month(self):
"""
Return the number of days in the month.
"""
return ccalendar.get_days_in_month(self.year, self.month)

daysinmonth = days_in_month

@property
def freqstr(self):
"""
Return the total number of days in the month.
"""
return getattr(self.freq, 'freqstr', self.freq)

@property
def is_month_start(self):
"""
Return True if date is first day of month.
"""
if self.freq is None:
# fast-path for non-business frequencies
return self.day == 1
return self._get_start_end_field('is_month_start')

@property
def is_month_end(self):
"""
Return True if date is last day of month.
"""
if self.freq is None:
# fast-path for non-business frequencies
return self.day == self.days_in_month
return self._get_start_end_field('is_month_end')

@property
def is_quarter_start(self):
"""
Return True if date is first day of the quarter.
"""
if self.freq is None:
# fast-path for non-business frequencies
return self.day == 1 and self.month % 3 == 1
return self._get_start_end_field('is_quarter_start')

@property
def is_quarter_end(self):
"""
Return True if date is last day of the quarter.
"""
if self.freq is None:
# fast-path for non-business frequencies
return (self.month % 3) == 0 and self.day == self.days_in_month
return self._get_start_end_field('is_quarter_end')

@property
def is_year_start(self):
"""
Return True if date is first day of the year.
"""
if self.freq is None:
# fast-path for non-business frequencies
return self.day == self.month == 1
return self._get_start_end_field('is_year_start')

@property
def is_year_end(self):
"""
Return True if date is last day of the year.
"""
if self.freq is None:
# fast-path for non-business frequencies
return self.month == 12 and self.day == 31
return self._get_start_end_field('is_year_end')

@property
def is_leap_year(self):
"""
Return True if year is a leap year.
"""
return bool(ccalendar.is_leapyear(self.year))

def tz_localize(self, tz, ambiguous='raise', nonexistent='raise',
Expand Down
11 changes: 0 additions & 11 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* lists: lrange(), lmap(), lzip(), lfilter()
* unicode: u() [no unicode builtin in Python 3]
* longs: long (int in Python 3)
* callable
* iterable method compatibility: iteritems, iterkeys, itervalues
* Uses the original method if available, otherwise uses items, keys, values.
* types:
Expand Down Expand Up @@ -378,14 +377,6 @@ class ResourceWarning(Warning):
string_and_binary_types = string_types + (binary_type,)


try:
# callable reintroduced in later versions of Python
callable = callable
except NameError:
def callable(obj):
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)


if PY2:
# In PY2 functools.wraps doesn't provide metadata pytest needs to generate
# decorated tests using parametrization. See pytest GH issue #2782
Expand All @@ -411,8 +402,6 @@ def wrapper(cls):
return metaclass(cls.__name__, cls.__bases__, orig_vars)
return wrapper

from collections import OrderedDict, Counter

if PY3:
def raise_with_traceback(exc, traceback=Ellipsis):
if traceback == Ellipsis:
Expand Down
4 changes: 3 additions & 1 deletion pandas/compat/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
_np_version_under1p13 = _nlv < LooseVersion('1.13')
_np_version_under1p14 = _nlv < LooseVersion('1.14')
_np_version_under1p15 = _nlv < LooseVersion('1.15')
_np_version_under1p16 = _nlv < LooseVersion('1.16')


if _nlv < '1.12':
Expand Down Expand Up @@ -64,5 +65,6 @@ def np_array_datetime64_compat(arr, *args, **kwargs):
__all__ = ['np',
'_np_version_under1p13',
'_np_version_under1p14',
'_np_version_under1p15'
'_np_version_under1p15',
'_np_version_under1p16'
]
2 changes: 1 addition & 1 deletion pandas/compat/numpy/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
and methods that are spread throughout the codebase. This module will make it
easier to adjust to future upstream changes in the analogous numpy signatures.
"""
from collections import OrderedDict

from numpy import ndarray

from pandas.compat import OrderedDict
from pandas.errors import UnsupportedFunctionCall
from pandas.util._validators import (
validate_args, validate_args_and_kwargs, validate_kwargs)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ def unique(values):
See Also
--------
pandas.Index.unique
pandas.Series.unique
Index.unique
Series.unique
Examples
--------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class Categorical(ExtensionArray, PandasObject):
See Also
--------
pandas.api.types.CategoricalDtype : Type for categorical data.
api.types.CategoricalDtype : Type for categorical data.
CategoricalIndex : An Index with an underlying ``Categorical``.
Notes
Expand Down
34 changes: 27 additions & 7 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""
Base and utility classes for pandas objects.
"""
from collections import OrderedDict
import textwrap
import warnings

import numpy as np

import pandas._libs.lib as lib
import pandas.compat as compat
from pandas.compat import PYPY, OrderedDict, builtins, map, range
from pandas.compat import PYPY, builtins, map, range
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
from pandas.util._decorators import Appender, Substitution, cache_readonly
Expand Down Expand Up @@ -376,7 +377,7 @@ def nested_renaming_depr(level=4):
# eg. {'A' : ['mean']}, normalize all to
# be list-likes
if any(is_aggregator(x) for x in compat.itervalues(arg)):
new_arg = compat.OrderedDict()
new_arg = OrderedDict()
for k, v in compat.iteritems(arg):
if not isinstance(v, (tuple, list, dict)):
new_arg[k] = [v]
Expand Down Expand Up @@ -444,22 +445,22 @@ def _agg(arg, func):
run the aggregations over the arg with func
return an OrderedDict
"""
result = compat.OrderedDict()
result = OrderedDict()
for fname, agg_how in compat.iteritems(arg):
result[fname] = func(fname, agg_how)
return result

# set the final keys
keys = list(compat.iterkeys(arg))
result = compat.OrderedDict()
result = OrderedDict()

# nested renamer
if is_nested_renamer:
result = list(_agg(arg, _agg_1dim).values())

if all(isinstance(r, dict) for r in result):

result, results = compat.OrderedDict(), result
result, results = OrderedDict(), result
for r in results:
result.update(r)
keys = list(compat.iterkeys(result))
Expand Down Expand Up @@ -1323,12 +1324,31 @@ def nunique(self, dropna=True):
Parameters
----------
dropna : boolean, default True
dropna : bool, default True
Don't include NaN in the count.
Returns
-------
nunique : int
int
See Also
--------
DataFrame.nunique: Method nunique for DataFrame.
Series.count: Count non-NA/null observations in the Series.
Examples
--------
>>> s = pd.Series([1, 3, 5, 7, 7])
>>> s
0 1
1 3
2 5
3 7
4 7
dtype: int64
>>> s.nunique()
4
"""
uniqs = self.unique()
n = len(uniqs)
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import collections
from collections import OrderedDict
from datetime import datetime, timedelta
from functools import partial
import inspect
Expand All @@ -13,7 +14,7 @@

from pandas._libs import lib, tslibs
import pandas.compat as compat
from pandas.compat import PY36, OrderedDict, iteritems
from pandas.compat import PY36, iteritems

from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
from pandas.core.dtypes.common import (
Expand Down
Loading

0 comments on commit b55b270

Please sign in to comment.