Skip to content
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

Add typing annotation to assert_index_equal #26535

Merged
merged 11 commits into from
Jun 8, 2019

Conversation

makbigc
Copy link
Contributor

@makbigc makbigc commented May 27, 2019

@codecov
Copy link

codecov bot commented May 27, 2019

Codecov Report

Merging #26535 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26535      +/-   ##
==========================================
- Coverage   91.76%   91.76%   -0.01%     
==========================================
  Files         174      174              
  Lines       50629    50631       +2     
==========================================
- Hits        46462    46461       -1     
- Misses       4167     4170       +3
Flag Coverage Δ
#multiple 90.3% <100%> (ø) ⬆️
#single 41.71% <100%> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/util/testing.py 90.72% <100%> (+0.12%) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 97% <0%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a516c1...453875e. Read the comment docs.

@codecov
Copy link

codecov bot commented May 27, 2019

Codecov Report

Merging #26535 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26535      +/-   ##
==========================================
- Coverage   91.78%   91.77%   -0.01%     
==========================================
  Files         174      174              
  Lines       50703    50706       +3     
==========================================
- Hits        46538    46537       -1     
- Misses       4165     4169       +4
Flag Coverage Δ
#multiple 90.37% <100%> (ø) ⬆️
#single 41.81% <100%> (-0.09%) ⬇️
Impacted Files Coverage Δ
pandas/util/testing.py 90.63% <100%> (+0.02%) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 96.88% <0%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf25c5c...de3fbf2. Read the comment docs.

check_exact=check_exact, obj=lobj)
# get_level_values may change dtype
_check_types(left.levels[level], right.levels[level], obj=obj)
if isinstance(left, MultiIndex) and isinstance(right, MultiIndex):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed to avoid type issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Otherwise, mypy showed
pandas/util/testing.py:608: error: "Index" has no attribute "levels"; maybe "nlevels"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just replace the existing condition then? Seems duplicative to have both checks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that if isinstance(left, MultiIndex) and if left.nlevels > 1 are equivalent so no need to have both (just the former).

Also does this have any impact on assertions given the check previously only looked at the left index and not both?

@jreback jreback added the Typing type annotations, mypy/pyright type checking label May 27, 2019
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We explicitly exclude the tests directory from mypy right now (see mypy.ini). Could you check any impacts of removing that from the blacklist as part of this?

@WillAyd WillAyd added this to the 0.25.0 milestone May 27, 2019
@makbigc
Copy link
Contributor Author

makbigc commented May 28, 2019

pandas/mypy.ini

Lines 5 to 6 in 19f693f

[mypy-pandas.conftest,pandas.tests.*]
ignore_errors=True

pandas/conftest and pandas/tests are excluded. The assert_*_equal are in pandas/util, mypy has been checking these assertion functions.

@makbigc
Copy link
Contributor Author

makbigc commented May 28, 2019

After removing pandas.tests.* only in mypy.ini, the following is mypy error:

pandas/tests/test_base.py:1232: error: Argument "freq" to "period_array" has incompatible type "str"; expected "Optional[Tick]"
pandas/tests/test_base.py:1266: error: Argument "freq" to "period_array" has incompatible type "str"; expected "Optional[Tick]"
pandas/tests/tseries/offsets/test_offsets_properties.py:43: error: Argument "min_value" to "datetimes" has incompatible type "Tuple[Any]"; expected "datetime"
pandas/tests/tseries/offsets/test_offsets_properties.py:43: error: Argument "max_value" to "datetimes" has incompatible type "Tuple[Any]"; expected "datetime"
pandas/tests/series/test_constructors.py:38: error: Need type annotation for 'x'
pandas/tests/series/test_constructors.py:43: error: Need type annotation for 'x'
pandas/tests/scalar/timestamp/test_rendering.py:14: error: Module has no attribute "__version__"
pandas/tests/io/test_sql.py:884: error: Incompatible types in assignment (expression has type "str", base class "_TestSQLApi" defined the type as "None")
pandas/tests/io/test_sql.py:1074: error: Incompatible types in assignment (expression has type "str", base class "_TestSQLApi" defined the type as "None")
pandas/tests/io/test_sql.py:1965: error: Definition of "flavor" in base class "_TestMySQLAlchemy" is incompatible with definition in base class "_TestSQLAlchemy"
pandas/tests/io/test_sql.py:1971: error: Definition of "flavor" in base class "_TestMySQLAlchemy" is incompatible with definition in base class "_TestSQLAlchemy"
pandas/tests/io/test_sql.py:1977: error: Definition of "flavor" in base class "_TestPostgreSQLAlchemy" is incompatible with definition in base class "_TestSQLAlchemy"
pandas/tests/io/test_sql.py:1983: error: Definition of "flavor" in base class "_TestPostgreSQLAlchemy" is incompatible with definition in base class "_TestSQLAlchemy"
pandas/tests/io/test_sql.py:1989: error: Definition of "flavor" in base class "_TestSQLiteAlchemy" is incompatible with definition in base class "_TestSQLAlchemy"
pandas/tests/io/test_sql.py:1994: error: Definition of "flavor" in base class "_TestSQLiteAlchemy" is incompatible with definition in base class "_TestSQLAlchemy"
pandas/tests/io/parser/conftest.py:11: error: Need type annotation for 'float_precision_choices'
pandas/tests/io/parser/conftest.py:30: error: Incompatible types in assignment (expression has type "str", base class "BaseParser" defined the type as "None")
pandas/tests/io/parser/conftest.py:43: error: Incompatible types in assignment (expression has type "str", base class "BaseParser" defined the type as "None")
pandas/tests/io/parser/conftest.py:63: error: Unsupported operand types for + ("List[CParser]" and "List[PythonParser]")
pandas/tests/io/json/test_ujson.py:4: error: Name 'json' already defined (by an import)
pandas/tests/io/formats/test_to_csv.py:320: error: Unexpected keyword argument "levels" for "MultiIndex"
pandas/tests/io/formats/test_to_csv.py:320: error: Unexpected keyword argument "codes" for "MultiIndex"
pandas/tests/io/formats/test_to_csv.py:320: error: Unexpected keyword argument "names" for "MultiIndex"
pandas/tests/io/formats/test_to_csv.py:324: error: Unexpected keyword argument "levels" for "MultiIndex"
pandas/tests/io/formats/test_to_csv.py:324: error: Unexpected keyword argument "codes" for "MultiIndex"
pandas/tests/io/formats/test_to_csv.py:324: error: Unexpected keyword argument "names" for "MultiIndex"
pandas/tests/indexing/test_coercion.py:802: error: List item 0 has incompatible type "int"; expected "str"
pandas/tests/indexing/test_coercion.py:802: error: List item 1 has incompatible type "int"; expected "str"
pandas/tests/indexing/test_coercion.py:803: error: List item 0 has incompatible type "float"; expected "str"
pandas/tests/indexing/test_coercion.py:803: error: List item 1 has incompatible type "float"; expected "str"
pandas/tests/indexing/test_coercion.py:804: error: List item 0 has incompatible type "complex"; expected "str"
pandas/tests/indexing/test_coercion.py:804: error: List item 1 has incompatible type "complex"; expected "str"
pandas/tests/indexing/test_coercion.py:805: error: List item 0 has incompatible type "bool"; expected "str"
pandas/tests/indexing/test_coercion.py:805: error: List item 1 has incompatible type "bool"; expected "str"
pandas/tests/indexes/interval/test_interval_tree.py:146: error: Argument 1 to "map" has incompatible type "Type[List[Any]]"; expected "Callable[[Tuple[int, ...]], List[_T]]"
pandas/tests/indexes/interval/test_interval_tree.py:153: error: Argument 1 to "map" has incompatible type "Type[List[Any]]"; expected "Callable[[Tuple[int, ...]], List[_T]]"
pandas/tests/extension/json/array.py:30: error: Need type annotation for 'na_value'
pandas/tests/arrays/test_period.py:239: error: Argument "freq" to "period_array" has incompatible type "str"; expected "Optional[Tick]"
pandas/tests/arrays/test_datetimelike.py:228: error: Incompatible types in assignment (expression has type "Type[DatetimeIndex]", base class "SharedTests" defined the type as "None")
pandas/tests/arrays/test_datetimelike.py:468: error: Incompatible types in assignment (expression has type "Type[TimedeltaIndex]", base class "SharedTests" defined the type as "None")
pandas/tests/arrays/test_datetimelike.py:578: error: Incompatible types in assignment (expression has type "Type[PeriodIndex]", base class "SharedTests" defined the type as "None")
pandas/tests/arrays/sparse/test_arithmetics.py:429: error: Incompatible types in assignment (expression has type "Type[SparseSeries]", base class "TestSparseArrayArithmetics" defined the type as "Type[SparseArray]")
pandas/tests/arithmetic/test_datetime64.py:2080: error: "DatetimeIndex" has no attribute "tz_localize"
pandas/tests/test_algos.py:730: error: Invalid signature "def (self: Any) -> Any"
pandas/tests/tseries/offsets/test_offsets.py:589: error: Incompatible types in assignment (expression has type "Type[BusinessDay]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_offsets.py:678: error: Argument 1 to "append" of "list" has incompatible type "Tuple[int, Dict[datetime, datetime]]"; expected "Tuple[BusinessDay, Dict[datetime, datetime]]"
pandas/tests/tseries/offsets/test_offsets.py:693: error: Argument 1 to "append" of "list" has incompatible type "Tuple[int, Dict[datetime, datetime]]"; expected "Tuple[BusinessDay, Dict[datetime, datetime]]"
pandas/tests/tseries/offsets/test_offsets.py:747: error: Incompatible types in assignment (expression has type "Type[BusinessHour]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_offsets.py:1429: error: Incompatible types in assignment (expression has type "Type[CustomBusinessHour]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_offsets.py:1672: error: Incompatible types in assignment (expression has type "Type[CustomBusinessDay]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_offsets.py:1764: error: Argument 1 to "append" of "list" has incompatible type "Tuple[int, Dict[datetime, datetime]]"; expected "Tuple[CustomBusinessDay, Dict[datetime, datetime]]"
pandas/tests/tseries/offsets/test_offsets.py:1779: error: Argument 1 to "append" of "list" has incompatible type "Tuple[int, Dict[datetime, datetime]]"; expected "Tuple[CustomBusinessDay, Dict[datetime, datetime]]"
pandas/tests/tseries/offsets/test_offsets.py:1922: error: Incompatible types in assignment (expression has type "Type[CustomBusinessMonthEnd]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_offsets.py:1978: error: Argument 1 to "append" of "list" has incompatible type "Tuple[int, Dict[datetime, datetime]]"; expected "Tuple[CustomBusinessMonthEnd, Dict[datetime, datetime]]"
pandas/tests/tseries/offsets/test_offsets.py:1986: error: Argument 1 to "append" of "list" has incompatible type "Tuple[int, Dict[datetime, datetime]]"; expected "Tuple[CustomBusinessMonthEnd, Dict[datetime, datetime]]"
pandas/tests/tseries/offsets/test_offsets.py:2039: error: Incompatible types in assignment (expression has type "Type[CustomBusinessMonthBegin]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_offsets.py:2095: error: Argument 1 to "append" of "list" has incompatible type "Tuple[int, Dict[datetime, datetime]]"; expected "Tuple[CustomBusinessMonthBegin, Dict[datetime, datetime]]"
pandas/tests/tseries/offsets/test_offsets.py:2103: error: Argument 1 to "append" of "list" has incompatible type "Tuple[int, Dict[datetime, datetime]]"; expected "Tuple[CustomBusinessMonthBegin, Dict[datetime, datetime]]"
pandas/tests/tseries/offsets/test_offsets.py:2156: error: Incompatible types in assignment (expression has type "Type[Week]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_offsets.py:2231: error: Incompatible types in assignment (expression has type "Type[WeekOfMonth]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_offsets.py:2332: error: Incompatible types in assignment (expression has type "Type[LastWeekOfMonth]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_offsets.py:2409: error: Incompatible types in assignment (expression has type "Type[SemiMonthEnd]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_offsets.py:2596: error: Incompatible types in assignment (expression has type "Type[SemiMonthBegin]", base class "Base" defined the type as "None")
pandas/tests/series/test_operators.py:694: error: "Type[Series]" has no attribute "div"
pandas/tests/series/test_operators.py:695: error: "Type[Series]" has no attribute "rdiv"
pandas/tests/indexing/test_loc.py:527: error: No overload variant of "slice" matches argument types "None", "str", "None"
pandas/tests/indexing/test_loc.py:527: note: Possible overload variant:
pandas/tests/indexing/test_loc.py:527: note:     def slice(self, start: Optional[int], stop: Optional[int], step: Optional[int] = ...) -> slice
pandas/tests/indexing/test_loc.py:527: note:     <1 more non-matching overload not shown>
pandas/tests/indexes/test_numeric.py:96: error: Incompatible types in assignment (expression has type "Type[Float64Index]", base class "Base" defined the type as "None")
pandas/tests/indexes/test_numeric.py:584: error: Incompatible types in assignment (expression has type "Type[Int64Index]", base class "Base" defined the type as "None")
pandas/tests/indexes/test_numeric.py:872: error: Incompatible types in assignment (expression has type "Type[UInt64Index]", base class "Base" defined the type as "None")
pandas/tests/indexes/test_category.py:20: error: Incompatible types in assignment (expression has type "Type[CategoricalIndex]", base class "Base" defined the type as "None")
pandas/tests/indexes/test_base.py:34: error: Incompatible types in assignment (expression has type "Type[Index]", base class "Base" defined the type as "None")
pandas/tests/indexes/test_base.py:452: error: Need type annotation for 'x'
pandas/tests/indexes/test_base.py:464: error: Need type annotation for 'x'
pandas/tests/indexes/test_base.py:466: error: Unexpected keyword argument "levels" for "MultiIndex"
pandas/tests/indexes/test_base.py:466: error: Unexpected keyword argument "codes" for "MultiIndex"
pandas/tests/indexes/test_base.py:1593: error: Slice index must be an integer or None
pandas/tests/indexes/test_base.py:1594: error: Slice index must be an integer or None
pandas/tests/indexes/test_base.py:1595: error: Slice index must be an integer or None
pandas/tests/indexes/test_base.py:1596: error: Slice index must be an integer or None
pandas/tests/indexes/test_base.py:1598: error: Slice index must be an integer or None
pandas/tests/indexes/test_base.py:1599: error: Slice index must be an integer or None
pandas/tests/indexes/test_base.py:1600: error: Slice index must be an integer or None
pandas/tests/indexes/test_base.py:1601: error: Slice index must be an integer or None
pandas/tests/indexes/test_base.py:1602: error: Slice index must be an integer or None
pandas/tests/indexes/test_base.py:2164: error: Incompatible types in assignment (expression has type "Type[Index]", base class "Base" defined the type as "None")
pandas/tests/indexes/test_base.py:2417: error: Too many arguments for "MultiIndex"
pandas/tests/indexes/test_base.py:2419: error: Too many arguments for "MultiIndex"
pandas/tests/indexes/test_base.py:2419: error: Unexpected keyword argument "names" for "MultiIndex"
pandas/tests/indexes/interval/test_interval.py:22: error: Incompatible types in assignment (expression has type "Type[IntervalIndex]", base class "Base" defined the type as "None")
pandas/tests/indexes/datetimes/test_tools.py:200: error: Module has no attribute "FixedOffset"
pandas/tests/indexes/datetimes/test_tools.py:204: error: Module has no attribute "FixedOffset"
pandas/tests/indexes/datetimes/test_tools.py:208: error: Module has no attribute "FixedOffset"
pandas/tests/indexes/datetimes/test_tools.py:210: error: Module has no attribute "FixedOffset"
pandas/tests/indexes/datetimes/test_tools.py:214: error: Module has no attribute "FixedOffset"
pandas/tests/indexes/datetimes/test_tools.py:216: error: Module has no attribute "FixedOffset"
pandas/tests/indexes/datetimes/test_tools.py:1816: error: Module has no attribute "FixedOffset"
pandas/tests/indexes/datetimes/test_tools.py:1818: error: Module has no attribute "FixedOffset"
pandas/tests/frame/test_convert_to.py:488: error: Argument 1 to "defaultdict" has incompatible type "Type[List[Any]]"; expected "Optional[Callable[[], Dict[str, float]]]"
pandas/tests/frame/test_constructors.py:35: error: Need type annotation for 'x'
pandas/tests/frame/test_constructors.py:41: error: Need type annotation for 'x'
pandas/tests/frame/test_constructors.py:54: error: Need type annotation for 'x'
pandas/tests/dtypes/test_inference.py:56: error: Need type annotation for 'x'
pandas/tests/dtypes/test_inference.py:239: error: Too many arguments for "tuple"
pandas/tests/dtypes/test_inference.py:239: error: Argument 1 to "tuple" has incompatible type "int"; expected "Iterable[Any]"
pandas/tests/computation/test_eval.py:1808: error: Dict entry 1 has incompatible type "str": "Type[ExprVisitor]"; expected "str": "Type[BaseExprVisitor]"
pandas/tests/api/test_api.py:33: error: Need type annotation for 'deprecated_modules'
pandas/tests/api/test_api.py:56: error: Need type annotation for 'deprecated_classes_in_future'
pandas/tests/api/test_api.py:90: error: Need type annotation for 'deprecated_funcs_in_future'
pandas/tests/api/test_api.py:93: error: Need type annotation for 'deprecated_funcs'
pandas/tests/tseries/offsets/test_yqm_offsets.py:386: error: Incompatible types in assignment (expression has type "Type[QuarterEnd]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_yqm_offsets.py:502: error: Incompatible types in assignment (expression has type "Type[BQuarterBegin]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_yqm_offsets.py:597: error: Incompatible types in assignment (expression has type "Type[BQuarterEnd]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_yqm_offsets.py:712: error: Incompatible types in assignment (expression has type "Type[YearBegin]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_yqm_offsets.py:804: error: Incompatible types in assignment (expression has type "Type[YearEnd]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_yqm_offsets.py:901: error: Incompatible types in assignment (expression has type "Type[BYearBegin]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_yqm_offsets.py:950: error: Incompatible types in assignment (expression has type "Type[BYearEnd]", base class "Base" defined the type as "None")
pandas/tests/tseries/offsets/test_yqm_offsets.py:997: error: Incompatible types in assignment (expression has type "Type[BYearEnd]", base class "Base" defined the type as "None")
pandas/tests/indexes/test_range.py:20: error: Incompatible types in assignment (expression has type "Type[RangeIndex]", base class "Base" defined the type as "None")
pandas/tests/indexes/timedeltas/test_timedelta.py:21: error: Incompatible types in assignment (expression has type "Type[TimedeltaIndex]", base class "Base" defined the type as "None")
pandas/tests/indexes/period/test_period.py:17: error: Incompatible types in assignment (expression has type "Type[PeriodIndex]", base class "Base" defined the type as "None")
pandas/tests/indexes/datetimes/test_datetimelike.py:10: error: Incompatible types in assignment (expression has type "Type[DatetimeIndex]", base class "Base" defined the type as "None")
pandas/tests/dtypes/test_common.py:295: error: Unsupported operand types for + ("List[Series]" and "List[str]")
pandas/tests/dtypes/test_common.py:312: error: Unsupported operand types for + ("List[Series]" and "List[object]")
pandas/tests/dtypes/test_common.py:334: error: Unsupported operand types for + ("List[Series]" and "List[str]")
pandas/tests/arrays/test_array.py:32: error: Argument "freq" to "period_array" has incompatible type "str"; expected "Optional[Tick]"
pandas/tests/arrays/test_array.py:36: error: Argument "freq" to "period_array" has incompatible type "str"; expected "Optional[Tick]"
pandas/tests/arrays/test_array.py:99: error: Argument "freq" to "period_array" has incompatible type "str"; expected "Optional[Tick]"
pandas/tests/arrays/test_array.py:129: error: Argument "freq" to "period_array" has incompatible type "str"; expected "Optional[Tick]"
pandas/tests/extension/test_sparse.py:305: error: Incompatible types in assignment (expression has type "None", base class "BaseArithmeticOpsTests" defined the type as "Type[TypeError]")
pandas/tests/extension/test_sparse.py:306: error: Incompatible types in assignment (expression has type "None", base class "BaseArithmeticOpsTests" defined the type as "Type[TypeError]")
pandas/tests/extension/test_sparse.py:307: error: Incompatible types in assignment (expression has type "None", base class "BaseArithmeticOpsTests" defined the type as "Type[TypeError]")
pandas/tests/extension/test_sparse.py:308: error: Incompatible types in assignment (expression has type "None", base class "BaseArithmeticOpsTests" defined the type as "Type[TypeError]")
pandas/tests/extension/test_numpy.py:263: error: Incompatible types in assignment (expression has type "None", base class "BaseArithmeticOpsTests" defined the type as "Type[TypeError]")
pandas/tests/extension/test_numpy.py:264: error: Incompatible types in assignment (expression has type "None", base class "BaseArithmeticOpsTests" defined the type as "Type[TypeError]")
pandas/tests/extension/test_numpy.py:265: error: Incompatible types in assignment (expression has type "None", base class "BaseArithmeticOpsTests" defined the type as "Type[TypeError]")
pandas/tests/extension/test_numpy.py:266: error: Incompatible types in assignment (expression has type "None", base class "BaseArithmeticOpsTests" defined the type as "Type[TypeError]")
pandas/tests/extension/json/test_json.py:108: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:108: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:112: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:112: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:131: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:131: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:139: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:139: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:156: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:156: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:160: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:160: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:179: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:179: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:235: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:235: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:248: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:248: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:277: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:277: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:295: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:295: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:299: error: Definition of "assert_series_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/json/test_json.py:299: error: Definition of "assert_frame_equal" in base class "BaseJSON" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:115: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:115: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:120: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:120: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:124: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:124: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:132: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:132: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:136: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:136: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:148: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:148: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:174: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:174: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:190: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:190: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:194: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:194: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:198: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:198: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:202: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:202: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:262: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:262: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:297: error: Definition of "assert_series_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"
pandas/tests/extension/decimal/test_decimal.py:297: error: Definition of "assert_frame_equal" in base class "BaseDecimal" is incompatible with definition in base class "BaseExtensionTests"

check_names: bool = True,
check_less_precise: Union[bool, int] = False,
check_exact: bool = True,
check_categorical=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you annotate this parameter as well?

check_exact=check_exact, obj=lobj)
# get_level_values may change dtype
_check_types(left.levels[level], right.levels[level], obj=obj)
if isinstance(left, MultiIndex) and isinstance(right, MultiIndex):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just replace the existing condition then? Seems duplicative to have both checks

@makbigc
Copy link
Contributor Author

makbigc commented May 28, 2019

@WillAyd Would you tell me more? I don't understand what you mean.
There is not type check for MultiIndex before. Removing one of the MultiIndex checks would result in mypy error.

check_less_precise: Union[bool, int] = False,
check_exact: bool = True,
check_categorical: bool = True,
obj: str = 'Index'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type should be None.

check_less_precise=False, check_exact=True,
check_categorical=True, obj='Index'):
def assert_index_equal(left: Index,
right: Index,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a raw Index, is it possible to add a typing.TypeVar to _typing.py:

AnyIndex = TypeVar('AnyIndex ', pd.Index, pd.RangeIndex, pd.Int64Index, pd.MultiIndex, + other index types...)

and then use that here (I'm not super aqianted with typing, so could be wrong)?

That would avoid the need to adapt the code below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is ok as all of these are Index subclasses

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point was that AnyIndex would capture .levels and other attributes that are not set on the base Index.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is OK too. MyPy would still complain about those attributes not existing on Index

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple comments and one update request

check_less_precise=False, check_exact=True,
check_categorical=True, obj='Index'):
def assert_index_equal(left: Index,
right: Index,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is OK too. MyPy would still complain about those attributes not existing on Index

check_less_precise: Union[bool, int] = False,
check_exact: bool = True,
check_categorical: bool = True,
obj: str = 'Index') -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a general comment but NoReturn may be applicable here at some point when we drop 3.5, though not sure if Optional[NoReturn] makes sense

# get_level_values may change dtype
_check_types(left.levels[level], right.levels[level], obj=obj)
if isinstance(left, MultiIndex) and isinstance(right, MultiIndex):
if left.nlevels > 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this line should be removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or alternately we could keep original code in tact and simply cast inside of this condition; that would prevent any actual code changes but give mypy the inference it needs that we are only working with MI in this branch.

I'd actually prefer that but @jreback may have differing thoughts

Copy link
Contributor

@jreback jreback Jun 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah maybe the cast inside the condition is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pardon me. I am not familiar with casting in Python. By casting, do you mean left = MuliIndex(left)? This is a construction of a new MuliIndex which result in type error in our case TypeError: Must pass both levels and labels.

Or one more type annotation?

left  # type: MultiIndex
right  # type: MultiIndex
_check_types(left.levels[level], right.levels[level], obj=obj)

mypy still regards left and right as Index.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WillAyd
Copy link
Member

WillAyd commented Jun 2, 2019 via email

@@ -599,6 +605,8 @@ def _get_ilevel_values(index, level):
check_less_precise=check_less_precise,
check_exact=check_exact, obj=lobj)
# get_level_values may change dtype
left = cast(MultiIndex, left)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move these to line 597? That is specifically where the inference of a new type should occur would logically fit better there

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit otherwise lgtm

check_less_precise: Union[bool, int] = False,
check_exact: bool = True,
check_categorical: bool = True,
obj: str = 'Index') -> Optional[None]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just do None for the return (Optional[None] I don't think makes sense)

@makbigc
Copy link
Contributor Author

makbigc commented Jun 6, 2019

Something wrong with CI. Travis test can't be finished.

@makbigc
Copy link
Contributor Author

makbigc commented Jun 8, 2019

@WillAyd All tests passed.

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm @jreback

@jreback jreback merged commit c865eec into pandas-dev:master Jun 8, 2019
@jreback
Copy link
Contributor

jreback commented Jun 8, 2019

thanks @makbigc very nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants