From 4933ba82530a04f0150f8ba64a18b53c60cb895a Mon Sep 17 00:00:00 2001 From: Vaibhav Vishal Date: Mon, 13 May 2019 20:45:28 +0530 Subject: [PATCH 01/10] fis type annotation --- mypy.ini | 3 --- pandas/core/indexes/base.py | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/mypy.ini b/mypy.ini index 54b2c59e1ba33..f6d528a13de2f 100644 --- a/mypy.ini +++ b/mypy.ini @@ -5,9 +5,6 @@ follow_imports=silent [mypy-pandas.conftest,pandas.tests.*] ignore_errors=True -[mypy-pandas.core.indexes.base] -ignore_errors=True - [mypy-pandas.core.indexes.datetimelike] ignore_errors=True diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index f7c562798ad52..bb12c2bc43a38 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -6,8 +6,8 @@ import numpy as np -from pandas._libs import ( - algos as libalgos, index as libindex, join as libjoin, lib) +from pandas._libs import algos as libalgos, index as libindex, lib +import pandas._libs.join as libjoin from pandas._libs.lib import is_datetime_array from pandas._libs.tslibs import OutOfBoundsDatetime, Timedelta, Timestamp from pandas._libs.tslibs.timezones import tz_compare From cb3c8753377372e6421da1a7116df03a26533d63 Mon Sep 17 00:00:00 2001 From: Vaibhav Vishal Date: Wed, 15 May 2019 12:07:08 +0530 Subject: [PATCH 02/10] fix some errors and remove the module from mypy.ini --- mypy.ini | 3 --- pandas/core/indexes/datetimes.py | 9 +++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/mypy.ini b/mypy.ini index f6d528a13de2f..a546a48e39a3c 100644 --- a/mypy.ini +++ b/mypy.ini @@ -8,9 +8,6 @@ ignore_errors=True [mypy-pandas.core.indexes.datetimelike] ignore_errors=True -[mypy-pandas.core.indexes.datetimes] -ignore_errors=True - [mypy-pandas.core.indexes.period] ignore_errors=True diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 6b9806f4d32f5..bec9b729aa9de 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -5,7 +5,8 @@ import numpy as np from pandas._libs import ( - Timestamp, index as libindex, join as libjoin, lib, tslib as libts) + Timestamp, index as libindex, lib, tslib as libts) +import pandas._libs.join as libjoin from pandas._libs.tslibs import ccalendar, fields, parsing, timezones from pandas.util._decorators import Appender, Substitution, cache_readonly @@ -1112,9 +1113,9 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None): _is_monotonic_decreasing = Index.is_monotonic_decreasing _is_unique = Index.is_unique - _timezone = cache_readonly(DatetimeArray._timezone.fget) - is_normalized = cache_readonly(DatetimeArray.is_normalized.fget) - _resolution = cache_readonly(DatetimeArray._resolution.fget) + _timezone = cache_readonly(DatetimeArray._timezone.fget) # type: ignore + is_normalized = cache_readonly(DatetimeArray.is_normalized.fget) # type: ignore + _resolution = cache_readonly(DatetimeArray._resolution.fget) # type: ignore strftime = ea_passthrough(DatetimeArray.strftime) _has_same_tz = ea_passthrough(DatetimeArray._has_same_tz) From ca7e8eba34820c8389d9383205f4f9e486a0feab Mon Sep 17 00:00:00 2001 From: Vaibhav Vishal Date: Wed, 15 May 2019 12:17:06 +0530 Subject: [PATCH 03/10] fix linting errors --- pandas/core/indexes/datetimes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index bec9b729aa9de..61ed0f4ca970f 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1114,8 +1114,10 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None): _is_unique = Index.is_unique _timezone = cache_readonly(DatetimeArray._timezone.fget) # type: ignore - is_normalized = cache_readonly(DatetimeArray.is_normalized.fget) # type: ignore - _resolution = cache_readonly(DatetimeArray._resolution.fget) # type: ignore + is_normalized = cache_readonly( + DatetimeArray.is_normalized.fget) # type: ignore + _resolution = cache_readonly( + DatetimeArray._resolution.fget) # type: ignore strftime = ea_passthrough(DatetimeArray.strftime) _has_same_tz = ea_passthrough(DatetimeArray._has_same_tz) From 10f1c4da5a30eaebb4959591a56a94de29bc844f Mon Sep 17 00:00:00 2001 From: Vaibhav Vishal Date: Fri, 17 May 2019 11:29:57 +0530 Subject: [PATCH 04/10] fix import sorting errors --- pandas/core/indexes/datetimes.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 61ed0f4ca970f..e45ee87c86e72 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -4,8 +4,7 @@ import numpy as np -from pandas._libs import ( - Timestamp, index as libindex, lib, tslib as libts) +from pandas._libs import Timestamp, index as libindex, lib, tslib as libts import pandas._libs.join as libjoin from pandas._libs.tslibs import ccalendar, fields, parsing, timezones from pandas.util._decorators import Appender, Substitution, cache_readonly From 247dd31e617eb12201656790097c53b87e6bcdf3 Mon Sep 17 00:00:00 2001 From: Vaibhav Vishal Date: Mon, 20 May 2019 11:30:47 +0530 Subject: [PATCH 05/10] fix the function signature of map to be consistent across different classes --- pandas/core/indexes/datetimelike.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 7454b015cb556..497d86b7ac64c 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -220,9 +220,9 @@ def __contains__(self, key): # Try to run function on index first, and then on elements of index # Especially important for group-by functionality - def map(self, f): + def map(self, mapper, na_action=None): try: - result = f(self) + result = mapper(self) # Try to use this result if we can if isinstance(result, np.ndarray): @@ -232,7 +232,7 @@ def map(self, f): raise TypeError('The map function must return an Index object') return result except Exception: - return self.astype(object).map(f) + return self.astype(object).map(mapper) def sort_values(self, return_indexer=False, ascending=True): """ From 9bfd9f2d32f3270d8a6c55272f61a334fc886490 Mon Sep 17 00:00:00 2001 From: Vaibhav Vishal Date: Mon, 20 May 2019 11:35:05 +0530 Subject: [PATCH 06/10] don't specify type of _data to make it's type consistent across classes --- pandas/core/indexes/datetimelike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 497d86b7ac64c..057b10a330f82 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -57,7 +57,7 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin): """ common ops mixin to support a unified interface datetimelike Index """ - _data = None # type: DatetimeLikeArrayMixin + _data = None # DatetimeLikeArrayMixin assumes subclasses are mutable, so these are # properties there. They can be made into cache_readonly for Index From 4680fd45a44145a42d59fa9d2224e44c934915b5 Mon Sep 17 00:00:00 2001 From: Vaibhav Vishal Date: Mon, 20 May 2019 11:50:28 +0530 Subject: [PATCH 07/10] fix signature of function _format_with_header to be consistent across classes --- pandas/core/indexes/datetimelike.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 057b10a330f82..55f09a449eb0c 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -430,8 +430,8 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs): # -------------------------------------------------------------------- # Rendering Methods - def _format_with_header(self, header, **kwargs): - return header + list(self._format_native_types(**kwargs)) + def _format_with_header(self, header, na_rep='NaN', **kwargs): + return header + list(self._format_native_types(na_rep, **kwargs)) @property def _formatter_func(self): From e59dc6aefb87f1c42564404498a4d10b88a5e492 Mon Sep 17 00:00:00 2001 From: Vaibhav Vishal Date: Mon, 20 May 2019 11:55:33 +0530 Subject: [PATCH 08/10] fix signature of function isin to be consistent acoross classes --- pandas/core/indexes/datetimelike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 55f09a449eb0c..a210ddae7717a 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -509,7 +509,7 @@ def __rsub__(self, other): cls.__rsub__ = __rsub__ - def isin(self, values): + def isin(self, values, level=None): """ Compute boolean array of whether each index value is found in the passed set of values. From 078d4902b3bf40b8986a2535104a55e78b4e8a9c Mon Sep 17 00:00:00 2001 From: Vaibhav Vishal Date: Mon, 20 May 2019 12:11:34 +0530 Subject: [PATCH 09/10] remove pandas.core.indexes.timedeltas from mypy.ini too as all its issues were solved automatically after fixing pandas.core.indexes.datetimes --- mypy.ini | 3 --- 1 file changed, 3 deletions(-) diff --git a/mypy.ini b/mypy.ini index c017f15a5b77f..3df8fd13a2a75 100644 --- a/mypy.ini +++ b/mypy.ini @@ -10,6 +10,3 @@ ignore_errors=True [mypy-pandas.core.indexes.period] ignore_errors=True - -[mypy-pandas.core.indexes.timedeltas] -ignore_errors=True \ No newline at end of file From c4a17b54427ae3e7f6c788f7d3976f0e8070b15d Mon Sep 17 00:00:00 2001 From: Vaibhav Vishal Date: Mon, 20 May 2019 13:07:29 +0530 Subject: [PATCH 10/10] fix tests (hopefully) --- pandas/core/indexes/datetimelike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index a210ddae7717a..092cec00228cd 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -430,7 +430,7 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs): # -------------------------------------------------------------------- # Rendering Methods - def _format_with_header(self, header, na_rep='NaN', **kwargs): + def _format_with_header(self, header, na_rep='NaT', **kwargs): return header + list(self._format_native_types(na_rep, **kwargs)) @property