Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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: 3 additions & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
- Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`)
- Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to ``False`` (:issue:`27600`)
- Removed the previously deprecated :attr:`Series.cat.categorical`, :attr:`Series.cat.index`, :attr:`Series.cat.name` (:issue:`24751`)
- Removed the previously deprecated ``time_rule`` keyword from (non-public) :func:`offsets.generate_range`, which has been moved to :func:`core.arrays._ranges.generate_range` (:issue:`24157`)
- :meth:`DataFrame.loc` or :meth:`Series.loc` with listlike indexers and missing labels will no longer reindex (:issue:`17295`)
- :meth:`DataFrame.to_excel` and :meth:`Series.to_excel` with non-existent columns will no longer reindex (:issue:`17295`)
- Removed the previously deprecated "by" keyword from :meth:`DataFrame.sort_index`, use :meth:`DataFrame.sort_values` instead (:issue:`10726`)
- Removed support for nested renaming in :meth:`DataFrame.aggregate`, :meth:`Series.aggregate`, :meth:`DataFrameGroupBy.aggregate`, :meth:`SeriesGroupBy.aggregate`, :meth:`Rolling.aggregate` (:issue:`18529`)
- Passing ``datetime64`` data to :class:`TimedeltaIndex` or ``timedelta64`` data to ``DatetimeIndex`` now raises ``TypeError`` (:issue:`23539`, :issue:`23937`)
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/computation/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _check_for_locals(expr: str, stack_level: int, parser: str):

def eval(
expr,
parser="pandas",
parser: str = "pandas",
engine=None,
truediv=_no_default,
local_dict=None,
Expand Down Expand Up @@ -306,16 +306,16 @@ def eval(
"multi-line expressions are only valid in the "
"context of data, use DataFrame.eval"
)
engine = _check_engine(engine)
_check_parser(parser)
_check_resolvers(resolvers)

ret = None
first_expr = True
target_modified = False

for expr in exprs:
expr = _convert_expression(expr)
engine = _check_engine(engine)
_check_parser(parser)
_check_resolvers(resolvers)
_check_for_locals(expr, level, parser)

# get our (possibly passed-in) scope
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def datetime_index(request):
"""
freqstr = request.param
# TODO: non-monotone indexes; NaTs, different start dates, timezones
pi = pd.date_range(start=pd.Timestamp("2000-01-01"), periods=100, freq=freqstr)
return pi
dti = pd.date_range(start=pd.Timestamp("2000-01-01"), periods=100, freq=freqstr)
return dti
Copy link
Member

Choose a reason for hiding this comment

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

Why not just return pd.date_range(...)



@pytest.fixture
Expand Down
103 changes: 34 additions & 69 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,11 @@
import pytest

import pandas as pd
from pandas import (
Categorical,
DataFrame,
Series,
SparseDtype,
compat,
date_range,
timedelta_range,
)
from pandas import Categorical, DataFrame, Series, compat, date_range, timedelta_range
import pandas.util.testing as tm


class SharedWithSparse:
"""
A collection of tests DataFrame and SparseDataFrame can share.

In generic tests on this class, use ``self._assert_frame_equal()`` and
``self._assert_series_equal()`` which are implemented in sub-classes
and dispatch correctly.
"""

def _assert_frame_equal(self, left, right):
"""Dispatch to frame class dependent assertion"""
raise NotImplementedError

def _assert_series_equal(self, left, right):
"""Dispatch to series class dependent assertion"""
raise NotImplementedError

class TestDataFrameMisc:
def test_copy_index_name_checking(self, float_frame):
# don't want to be able to modify the index stored elsewhere after
# making a copy
Expand Down Expand Up @@ -141,16 +117,16 @@ def test_tab_completion(self):
def test_not_hashable(self):
empty_frame = DataFrame()

df = self.klass([1])
msg = "'(Sparse)?DataFrame' objects are mutable, thus they cannot be hashed"
df = DataFrame([1])
msg = "'DataFrame' objects are mutable, thus they cannot be hashed"
with pytest.raises(TypeError, match=msg):
hash(df)
with pytest.raises(TypeError, match=msg):
hash(empty_frame)

def test_new_empty_index(self):
df1 = self.klass(np.random.randn(0, 3))
df2 = self.klass(np.random.randn(0, 3))
df1 = DataFrame(np.random.randn(0, 3))
df2 = DataFrame(np.random.randn(0, 3))
df1.index.name = "foo"
assert df2.index.name is None

Expand All @@ -161,7 +137,7 @@ def test_array_interface(self, float_frame):
assert result.index is float_frame.index
assert result.columns is float_frame.columns

self._assert_frame_equal(result, float_frame.apply(np.sqrt))
tm.assert_frame_equal(result, float_frame.apply(np.sqrt))

def test_get_agg_axis(self, float_frame):
cols = float_frame._get_agg_axis(0)
Expand All @@ -187,9 +163,9 @@ def test_nonzero(self, float_frame, float_string_frame):
assert not df.empty

def test_iteritems(self):
df = self.klass([[1, 2, 3], [4, 5, 6]], columns=["a", "a", "b"])
df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=["a", "a", "b"])
for k, v in df.items():
assert isinstance(v, self.klass._constructor_sliced)
assert isinstance(v, DataFrame._constructor_sliced)

def test_items(self):
# GH 17213, GH 13918
Expand All @@ -206,23 +182,23 @@ def test_iter(self, float_frame):
def test_iterrows(self, float_frame, float_string_frame):
for k, v in float_frame.iterrows():
exp = float_frame.loc[k]
self._assert_series_equal(v, exp)
tm.assert_series_equal(v, exp)

for k, v in float_string_frame.iterrows():
exp = float_string_frame.loc[k]
self._assert_series_equal(v, exp)
tm.assert_series_equal(v, exp)

def test_iterrows_iso8601(self):
# GH 19671
s = self.klass(
s = DataFrame(
{
"non_iso8601": ["M1701", "M1802", "M1903", "M2004"],
"iso8601": date_range("2000-01-01", periods=4, freq="M"),
}
)
for k, v in s.iterrows():
exp = s.loc[k]
self._assert_series_equal(v, exp)
tm.assert_series_equal(v, exp)

def test_iterrows_corner(self):
# gh-12222
Expand All @@ -248,19 +224,19 @@ def test_iterrows_corner(self):

def test_itertuples(self, float_frame):
for i, tup in enumerate(float_frame.itertuples()):
s = self.klass._constructor_sliced(tup[1:])
s = DataFrame._constructor_sliced(tup[1:])
s.name = tup[0]
expected = float_frame.iloc[i, :].reset_index(drop=True)
self._assert_series_equal(s, expected)
tm.assert_series_equal(s, expected)

df = self.klass(
df = DataFrame(
{"floats": np.random.randn(5), "ints": range(5)}, columns=["floats", "ints"]
)

for tup in df.itertuples(index=False):
assert isinstance(tup[1], int)

df = self.klass(data={"a": [1, 2, 3], "b": [4, 5, 6]})
df = DataFrame(data={"a": [1, 2, 3], "b": [4, 5, 6]})
dfaa = df[["a", "a"]]

assert list(dfaa.itertuples()) == [(0, 1, 1), (1, 2, 2), (2, 3, 3)]
Expand Down Expand Up @@ -315,7 +291,7 @@ def test_sequence_like_with_categorical(self):
def test_len(self, float_frame):
assert len(float_frame) == len(float_frame.index)

def test_values(self, float_frame, float_string_frame):
def test_values_mixed_dtypes(self, float_frame, float_string_frame):
frame = float_frame
arr = frame.values

Expand All @@ -332,7 +308,7 @@ def test_values(self, float_frame, float_string_frame):
arr = float_string_frame[["foo", "A"]].values
assert arr[0, 0] == "bar"

df = self.klass({"complex": [1j, 2j, 3j], "real": [1, 2, 3]})
df = DataFrame({"complex": [1j, 2j, 3j], "real": [1, 2, 3]})
arr = df.values
assert arr[0, 0] == 1j

Expand Down Expand Up @@ -372,17 +348,17 @@ def test_transpose(self, float_frame):

# mixed type
index, data = tm.getMixedTypeDict()
mixed = self.klass(data, index=index)
mixed = DataFrame(data, index=index)

mixed_T = mixed.T
for col, s in mixed_T.items():
assert s.dtype == np.object_

def test_swapaxes(self):
df = self.klass(np.random.randn(10, 5))
self._assert_frame_equal(df.T, df.swapaxes(0, 1))
self._assert_frame_equal(df.T, df.swapaxes(1, 0))
self._assert_frame_equal(df, df.swapaxes(0, 0))
df = DataFrame(np.random.randn(10, 5))
tm.assert_frame_equal(df.T, df.swapaxes(0, 1))
tm.assert_frame_equal(df.T, df.swapaxes(1, 0))
tm.assert_frame_equal(df, df.swapaxes(0, 0))
msg = (
"No axis named 2 for object type"
r" <class 'pandas.core(.sparse)?.frame.(Sparse)?DataFrame'>"
Expand Down Expand Up @@ -413,7 +389,7 @@ def test_more_values(self, float_string_frame):
assert values.shape[1] == len(float_string_frame.columns)

def test_repr_with_mi_nat(self, float_string_frame):
df = self.klass(
df = DataFrame(
{"X": [1, 2]}, index=[[pd.NaT, pd.Timestamp("20130101")], ["a", "b"]]
)
result = repr(df)
Expand All @@ -430,26 +406,26 @@ def test_series_put_names(self, float_string_frame):
assert v.name == k

def test_empty_nonzero(self):
df = self.klass([1, 2, 3])
df = DataFrame([1, 2, 3])
assert not df.empty
df = self.klass(index=[1], columns=[1])
df = DataFrame(index=[1], columns=[1])
assert not df.empty
df = self.klass(index=["a", "b"], columns=["c", "d"]).dropna()
df = DataFrame(index=["a", "b"], columns=["c", "d"]).dropna()
assert df.empty
assert df.T.empty
empty_frames = [
self.klass(),
self.klass(index=[1]),
self.klass(columns=[1]),
self.klass({1: []}),
DataFrame(),
DataFrame(index=[1]),
DataFrame(columns=[1]),
DataFrame({1: []}),
]
for df in empty_frames:
assert df.empty
assert df.T.empty

def test_with_datetimelikes(self):

df = self.klass(
df = DataFrame(
{
"A": date_range("20130101", periods=10),
"B": timedelta_range("1 day", periods=10),
Expand All @@ -458,20 +434,9 @@ def test_with_datetimelikes(self):
t = df.T

result = t.dtypes.value_counts()
if self.klass is DataFrame:
expected = Series({np.dtype("object"): 10})
else:
expected = Series({SparseDtype(dtype=object): 10})
expected = Series({np.dtype("object"): 10})
tm.assert_series_equal(result, expected)


class TestDataFrameMisc(SharedWithSparse):

klass = DataFrame
# SharedWithSparse tests use generic, klass-agnostic assertion
_assert_frame_equal = staticmethod(tm.assert_frame_equal)
_assert_series_equal = staticmethod(tm.assert_series_equal)

def test_values(self, float_frame):
float_frame.values[:, 0] = 5.0
assert (float_frame.values[:, 0] == 5).all()
Expand Down
Loading