Skip to content

Commit

Permalink
fix more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 committed Aug 19, 2021
1 parent 7afc611 commit 33bb44f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 26 deletions.
8 changes: 5 additions & 3 deletions pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@

import pandas as pd
from pandas import (
Float64Index,
Index,
Int64Index,
RangeIndex,
Series,
Timedelta,
TimedeltaIndex,
UInt64Index,
array,
)
import pandas._testing as tm
from pandas.core import ops
from pandas.core.api import (
Float64Index,
Int64Index,
UInt64Index,
)
from pandas.core.computation import expressions as expr


Expand Down
23 changes: 14 additions & 9 deletions pandas/tests/arithmetic/test_timedelta64.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
timedelta_range,
)
import pandas._testing as tm
from pandas.core.api import (
Float64Index,
Int64Index,
UInt64Index,
)
from pandas.tests.arithmetic.common import (
assert_invalid_addsub_type,
assert_invalid_comparison,
Expand Down Expand Up @@ -489,10 +494,10 @@ def test_addition_ops(self):
# random indexes
msg = "Addition/subtraction of integers and integer-arrays"
with pytest.raises(TypeError, match=msg):
tdi + pd.Int64Index([1, 2, 3])
tdi + Int64Index([1, 2, 3])

# this is a union!
# pytest.raises(TypeError, lambda : pd.Int64Index([1,2,3]) + tdi)
# pytest.raises(TypeError, lambda : Int64Index([1,2,3]) + tdi)

result = tdi + dti # name will be reset
expected = DatetimeIndex(["20130102", NaT, "20130105"])
Expand Down Expand Up @@ -1570,9 +1575,9 @@ def test_tdi_mul_float_series(self, box_with_array):
"other",
[
np.arange(1, 11),
pd.Int64Index(range(1, 11)),
pd.UInt64Index(range(1, 11)),
pd.Float64Index(range(1, 11)),
Int64Index(range(1, 11)),
UInt64Index(range(1, 11)),
Float64Index(range(1, 11)),
pd.RangeIndex(1, 11),
],
ids=lambda x: type(x).__name__,
Expand Down Expand Up @@ -1642,7 +1647,7 @@ def test_td64arr_div_tdlike_scalar(self, two_hours, box_with_array):
xbox = np.ndarray if box is pd.array else box

rng = timedelta_range("1 days", "10 days", name="foo")
expected = pd.Float64Index((np.arange(10) + 1) * 12, name="foo")
expected = Float64Index((np.arange(10) + 1) * 12, name="foo")

rng = tm.box_expected(rng, box)
expected = tm.box_expected(expected, xbox)
Expand Down Expand Up @@ -1685,7 +1690,7 @@ def test_td64arr_div_tdlike_scalar_with_nat(self, two_hours, box_with_array):
xbox = np.ndarray if box is pd.array else box

rng = TimedeltaIndex(["1 days", NaT, "2 days"], name="foo")
expected = pd.Float64Index([12, np.nan, 24], name="foo")
expected = Float64Index([12, np.nan, 24], name="foo")

rng = tm.box_expected(rng, box)
expected = tm.box_expected(expected, xbox)
Expand All @@ -1703,7 +1708,7 @@ def test_td64arr_div_td64_ndarray(self, box_with_array):
xbox = np.ndarray if box is pd.array else box

rng = TimedeltaIndex(["1 days", NaT, "2 days"])
expected = pd.Float64Index([12, np.nan, 24])
expected = Float64Index([12, np.nan, 24])

rng = tm.box_expected(rng, box)
expected = tm.box_expected(expected, xbox)
Expand Down Expand Up @@ -1846,7 +1851,7 @@ def test_td64arr_floordiv_tdlike_scalar(self, two_hours, box_with_array):
xbox = np.ndarray if box is pd.array else box

tdi = timedelta_range("1 days", "10 days", name="foo")
expected = pd.Int64Index((np.arange(10) + 1) * 12, name="foo")
expected = Int64Index((np.arange(10) + 1) * 12, name="foo")

tdi = tm.box_expected(tdi, box)
expected = tm.box_expected(expected, xbox)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/arrays/categorical/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
timedelta_range,
)
import pandas._testing as tm
from pandas.core.api import Int64Index


class TestCategoricalConstructors:
Expand Down Expand Up @@ -71,7 +72,7 @@ def test_constructor_empty(self):
tm.assert_index_equal(c.categories, expected)

c = Categorical([], categories=[1, 2, 3])
expected = pd.Int64Index([1, 2, 3])
expected = Int64Index([1, 2, 3])
tm.assert_index_equal(c.categories, expected)

def test_constructor_empty_boolean(self):
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/arrays/sparse/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pandas as pd
from pandas import isna
import pandas._testing as tm
from pandas.core.api import Int64Index
from pandas.core.arrays.sparse import (
SparseArray,
SparseDtype,
Expand Down Expand Up @@ -1309,7 +1310,7 @@ def test_dropna(fill_value):
tm.assert_sp_array_equal(arr.dropna(), exp)

df = pd.DataFrame({"a": [0, 1], "b": arr})
expected_df = pd.DataFrame({"a": [1], "b": exp}, index=pd.Int64Index([1]))
expected_df = pd.DataFrame({"a": [1], "b": exp}, index=Int64Index([1]))
tm.assert_equal(df.dropna(), expected_df)


Expand Down
11 changes: 8 additions & 3 deletions pandas/tests/dtypes/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import pandas as pd
import pandas._testing as tm
from pandas.core.api import (
Float64Index,
Int64Index,
UInt64Index,
)


class TestABCClasses:
Expand All @@ -23,9 +28,9 @@ class TestABCClasses:
timedelta_array = pd.core.arrays.TimedeltaArray(timedelta_index)

abc_pairs = [
("ABCInt64Index", pd.Int64Index([1, 2, 3])),
("ABCUInt64Index", pd.UInt64Index([1, 2, 3])),
("ABCFloat64Index", pd.Float64Index([1, 2, 3])),
("ABCInt64Index", Int64Index([1, 2, 3])),
("ABCUInt64Index", UInt64Index([1, 2, 3])),
("ABCFloat64Index", Float64Index([1, 2, 3])),
("ABCMultiIndex", multi_index),
("ABCDatetimeIndex", datetime_index),
("ABCRangeIndex", pd.RangeIndex(3)),
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/dtypes/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
import pandas as pd
from pandas import (
DatetimeIndex,
Float64Index,
NaT,
Series,
TimedeltaIndex,
date_range,
)
import pandas._testing as tm
from pandas.core.api import Float64Index

now = pd.Timestamp.now()
utcnow = pd.Timestamp.now("UTC")
Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/series/indexing/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pandas as pd
from pandas import Series
import pandas._testing as tm
from pandas.core.api import Float64Index


def test_get():
Expand Down Expand Up @@ -64,7 +65,7 @@ def test_get():
54,
]
),
index=pd.Float64Index(
index=Float64Index(
[
25.0,
36.0,
Expand Down Expand Up @@ -111,7 +112,7 @@ def test_get():

def test_get_nan():
# GH 8569
s = pd.Float64Index(range(10)).to_series()
s = Float64Index(range(10)).to_series()
assert s.get(np.nan) is None
assert s.get(np.nan, default="Missing") == "Missing"

Expand All @@ -120,7 +121,7 @@ def test_get_nan_multiple():
# GH 8569
# ensure that fixing "test_get_nan" above hasn't broken get
# with multiple elements
s = pd.Float64Index(range(10)).to_series()
s = Float64Index(range(10)).to_series()

idx = [2, 30]
assert s.get(idx) is None
Expand Down
15 changes: 10 additions & 5 deletions pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ def infer_freq(index, warn: bool = True) -> str | None:
>>> pd.infer_freq(idx)
'D'
"""
import pandas as pd
from pandas.core.api import (
DatetimeIndex,
Float64Index,
Index,
Int64Index,
)

if isinstance(index, ABCSeries):
values = index._values
Expand Down Expand Up @@ -182,15 +187,15 @@ def infer_freq(index, warn: bool = True) -> str | None:
inferer = _TimedeltaFrequencyInferer(index, warn=warn)
return inferer.get_freq()

if isinstance(index, pd.Index) and not isinstance(index, pd.DatetimeIndex):
if isinstance(index, (pd.Int64Index, pd.Float64Index)):
if isinstance(index, Index) and not isinstance(index, DatetimeIndex):
if isinstance(index, (Int64Index, Float64Index)):
raise TypeError(
f"cannot infer freq from a non-convertible index type {type(index)}"
)
index = index._values

if not isinstance(index, pd.DatetimeIndex):
index = pd.DatetimeIndex(index)
if not isinstance(index, DatetimeIndex):
index = DatetimeIndex(index)

inferer = _FrequencyInferer(index, warn=warn)
return inferer.get_freq()
Expand Down

0 comments on commit 33bb44f

Please sign in to comment.