Skip to content

Sync Fork from Upstream Repo #4

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

Merged
merged 4 commits into from
Jan 12, 2020
Merged
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
7 changes: 0 additions & 7 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ cdef class DatetimeEngine(Int64Engine):
conv = maybe_datetimelike_to_i8(val)
loc = values.searchsorted(conv, side='left')
except TypeError:
self._date_check_type(val)
raise KeyError(val)

if loc == len(values) or values[loc] != conv:
Expand All @@ -470,12 +469,6 @@ cdef class DatetimeEngine(Int64Engine):
val = maybe_datetimelike_to_i8(val)
return self.mapping.get_item(val)
except (TypeError, ValueError):
self._date_check_type(val)
raise KeyError(val)

cdef inline _date_check_type(self, object val):
hash(val)
if not util.is_integer_object(val):
raise KeyError(val)

def get_indexer(self, values):
Expand Down
29 changes: 21 additions & 8 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,28 @@ def pytest_runtest_setup(item):
pytest.skip("skipping high memory test since --run-high-memory was not set")


# Configurations for all tests and all test modules


@pytest.fixture(autouse=True)
def configure_tests():
"""
Configure settings for all tests and test modules.
"""
pd.set_option("chained_assignment", "raise")


# For running doctests: make np and pd names available


@pytest.fixture(autouse=True)
def add_imports(doctest_namespace):
"""
Make `np` and `pd` names available for doctests.
"""
doctest_namespace["np"] = np
doctest_namespace["pd"] = pd


@pytest.fixture(params=["bsr", "coo", "csc", "csr", "dia", "dok", "lil"])
def spmatrix(request):
"""
Yields scipy sparse matrix classes.
"""
from scipy import sparse

return getattr(sparse, request.param + "_matrix")
Expand All @@ -92,8 +95,8 @@ def spmatrix(request):
@pytest.fixture(params=[0, 1, "index", "columns"], ids=lambda x: f"axis {repr(x)}")
def axis(request):
"""
Fixture for returning the axis numbers of a DataFrame.
"""
Fixture for returning the axis numbers of a DataFrame.
"""
return request.param


Expand Down Expand Up @@ -237,6 +240,10 @@ def all_boolean_reductions(request):

@pytest.fixture(params=list(_cython_table))
def cython_table_items(request):
"""
Yields a tuple of a function and its corresponding name. Correspond to
the list of aggregator "Cython functions" used on selected table items.
"""
return request.param


Expand Down Expand Up @@ -337,6 +344,9 @@ def writable(request):

@pytest.fixture(scope="module")
def datetime_tz_utc():
"""
Yields the UTC timezone object from the datetime module.
"""
return timezone.utc


Expand All @@ -358,6 +368,9 @@ def join_type(request):

@pytest.fixture
def strict_data_files(pytestconfig):
"""
Returns the configuration for the test setting `--strict-data-files`.
"""
return pytestconfig.getoption("--strict-data-files")


Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ def __arrow_array__(self, type=None):
if self.freqstr != type.freq:
raise TypeError(
"Not supported to convert PeriodArray to array with different"
" 'freq' ({0} vs {1})".format(self.freqstr, type.freq)
f" 'freq' ({self.freqstr} vs {type.freq})"
)
else:
raise TypeError(
"Not supported to convert PeriodArray to '{0}' type".format(type)
f"Not supported to convert PeriodArray to '{type}' type"
)

period_type = ArrowPeriodType(self.freqstr)
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
from pandas.tseries.frequencies import to_offset
from pandas.tseries.offsets import Tick

_BAD_DTYPE = "dtype {dtype} cannot be converted to timedelta64[ns]"


def _is_convertible_to_td(key):
return isinstance(key, (Tick, timedelta, np.timedelta64, str))
Expand Down Expand Up @@ -1064,7 +1062,7 @@ def _validate_td64_dtype(dtype):
raise ValueError(msg)

if not is_dtype_equal(dtype, _TD_DTYPE):
raise ValueError(_BAD_DTYPE.format(dtype=dtype))
raise ValueError(f"dtype {dtype} cannot be converted to timedelta64[ns]")

return dtype

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,11 @@ def ensure_python_int(value: Union[int, np.integer]) -> int:
"""
if not is_scalar(value):
raise TypeError(f"Value needs to be a scalar value, was type {type(value)}")
msg = "Wrong type {} for value {}"
try:
new_value = int(value)
assert new_value == value
except (TypeError, ValueError, AssertionError):
raise TypeError(msg.format(type(value), value))
raise TypeError(f"Wrong type {type(value)} for value {value}")
return new_value


Expand Down
3 changes: 1 addition & 2 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,11 @@ def __eq__(self, other: Any) -> bool:
return hash(self) == hash(other)

def __repr__(self) -> str_type:
tpl = "CategoricalDtype(categories={data}ordered={ordered})"
if self.categories is None:
data = "None, "
else:
data = self.categories._format_data(name=type(self).__name__)
return tpl.format(data=data, ordered=self.ordered)
return f"CategoricalDtype(categories={data}ordered={self.ordered})"

@staticmethod
def _hash_categories(categories, ordered: Ordered = True) -> int:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,7 @@ def _verbose_repr():
dtype = self.dtypes.iloc[i]
col = pprint_thing(col)

line_no = _put_str(" {num}".format(num=i), space_num)
line_no = _put_str(f" {i}", space_num)
count = ""
if show_counts:
count = counts.iloc[i]
Expand Down