Skip to content

Confirm timedelta algos work #12465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ For Python 2.7, you can install the ``mingw`` compiler which will work equivalen

or use the `Microsoft Visual Studio VC++ compiler for Python <https://www.microsoft.com/en-us/download/details.aspx?id=44266>`__. Note that you have to check the ``x64`` box to install the ``x64`` extension building capability as this is not installed by default.

For Python 3.4, you can download and install the `Windows 7.1 SDK <https://www.microsoft.com/en-us/download/details.aspx?id=8279>`__
For Python 3.4, you can download and install the `Windows 7.1 SDK <https://www.microsoft.com/en-us/download/details.aspx?id=8279>`__. Read the references below as there may be various gotchas during the installation.

For Python 3.5, you can download and install the `Visual Studio 2015 Community Edition <https://www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs.aspx>`__.

Here are some references:
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ def test_mode(self):
assert_series_equal(s.mode(), Series(['2011-01-03', '2013-01-02'],
dtype='M8[ns]'))

# GH 5986
s = Series(['1 days', '-1 days', '0 days'], dtype='timedelta64[ns]')
assert_series_equal(s.mode(), Series([], dtype='timedelta64[ns]'))

s = Series(['1 day', '1 day', '-1 day', '-1 day 2 min', '2 min', '2 min'], dtype='timedelta64[ns]')
assert_series_equal(s.mode(), Series(['2 min', '1 day'], dtype='timedelta64[ns]'))

def test_prod(self):
self._check_stat_op('prod', np.prod)

Expand Down Expand Up @@ -1015,6 +1022,12 @@ def test_rank(self):
iranks = iseries.rank()
assert_series_equal(iranks, exp)

# GH 5968
iseries = Series([1e-50, 1e-100, 1e-20, 1e-2, 1e-20 + 1e-30, 1e-1, pd.NaT], dtype='timedelta64[ns]')
exp = Series([2, 1, 3, 5, 4, 6, 7])
iranks = iseries.rank()
assert_series_equal(iranks, exp)

values = np.array(
[-50, -1, -1e-20, -1e-25, -1e-50, 0, 1e-40, 1e-20, 1e-10, 2, 40
], dtype='float64')
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ def test_datelike(self):
[0, 0, 0, 1, 1, 0], dtype=np.int64))
self.assert_numpy_array_equal(uniques, pd.PeriodIndex([v1, v2]))

# GH 5986
v1 = pd.to_timedelta('1 day 1 min')
v2 = pd.to_timedelta('1 day')
x = Series([v1, v2, v1, v1, v2, v2, v1])
labels, uniques = algos.factorize(x)
self.assert_numpy_array_equal(labels, np.array(
[0, 1, 0, 0, 1, 1, 0], dtype=np.int64))
self.assert_numpy_array_equal(uniques, pd.to_timedelta([v1, v2]))

labels, uniques = algos.factorize(x, sort=True)
self.assert_numpy_array_equal(labels, np.array(
[1, 0, 1, 1, 0, 0, 1], dtype=np.int64))
self.assert_numpy_array_equal(uniques, pd.to_timedelta([v2, v1]))

def test_factorize_nan(self):
# nan should map to na_sentinel, not reverse_indexer[na_sentinel]
# rizer.factorize should not raise an exception if na_sentinel indexes
Expand Down