-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
DEPR: Warn on empty Series dtype inference #20802
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -954,7 +954,11 @@ def _map_values(self, mapper, na_action=None): | |
# we specify the keys here to handle the | ||
# possibility that they are tuples | ||
from pandas import Series | ||
mapper = Series(mapper) | ||
if len(mapper) == 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might be worthwhile to make a function in pandas.core.dtypes.cast.maybe_infer_1d_array_dtype |
||
mapper_dtype = 'float' | ||
else: | ||
mapper_dtype = None | ||
mapper = Series(mapper, dtype=mapper_dtype) | ||
|
||
if isinstance(mapper, ABCSeries): | ||
# Since values were input this means we came from either | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5399,7 +5399,11 @@ def fillna(self, value=None, method=None, axis=None, inplace=False, | |
if self.ndim == 1: | ||
if isinstance(value, (dict, ABCSeries)): | ||
from pandas import Series | ||
value = Series(value) | ||
if len(value) == 0: | ||
series_dtype = 'float' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
else: | ||
series_dtype = None | ||
value = Series(value, dtype=series_dtype) | ||
elif not is_list_like(value): | ||
pass | ||
else: | ||
|
@@ -9376,13 +9380,13 @@ def _doc_parms(cls): | |
-------- | ||
By default, the sum of an empty or all-NA Series is ``0``. | ||
|
||
>>> pd.Series([]).sum() # min_count=0 is the default | ||
>>> pd.Series([], dtype='float').sum() # min_count=0 is the default | ||
0.0 | ||
|
||
This can be controlled with the ``min_count`` parameter. For example, if | ||
you'd like the sum of an empty series to be NaN, pass ``min_count=1``. | ||
|
||
>>> pd.Series([]).sum(min_count=1) | ||
>>> pd.Series([], dtype='float').sum(min_count=1) | ||
nan | ||
|
||
Thanks to the ``skipna`` parameter, ``min_count`` handles all-NA and | ||
|
@@ -9400,12 +9404,12 @@ def _doc_parms(cls): | |
-------- | ||
By default, the product of an empty or all-NA Series is ``1`` | ||
|
||
>>> pd.Series([]).prod() | ||
>>> pd.Series([], dtype='float').prod() | ||
1.0 | ||
|
||
This can be controlled with the ``min_count`` parameter | ||
|
||
>>> pd.Series([]).prod(min_count=1) | ||
>>> pd.Series([], dtype='float').prod(min_count=1) | ||
nan | ||
|
||
Thanks to the ``skipna`` parameter, ``min_count`` handles all-NA and | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,6 @@ | |
is_datetime64_any_dtype, | ||
is_datetime64tz_dtype, | ||
is_timedelta64_dtype, | ||
is_hashable, | ||
needs_i8_conversion, | ||
is_iterator, is_list_like, | ||
is_scalar) | ||
|
@@ -1313,33 +1312,9 @@ def _get_names(self): | |
return FrozenList((self.name, )) | ||
|
||
def _set_names(self, values, level=None): | ||
""" | ||
Set new names on index. Each name has to be a hashable type. | ||
|
||
Parameters | ||
---------- | ||
values : str or sequence | ||
name(s) to set | ||
level : int, level name, or sequence of int/level names (default None) | ||
If the index is a MultiIndex (hierarchical), level(s) to set (None | ||
for all levels). Otherwise level must be None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like you have some extra commits? |
||
|
||
Raises | ||
------ | ||
TypeError if each name is not hashable. | ||
""" | ||
if not is_list_like(values): | ||
raise ValueError('Names must be a list-like') | ||
if len(values) != 1: | ||
raise ValueError('Length of new names must be 1, got %d' % | ||
len(values)) | ||
|
||
# GH 20527 | ||
# All items in 'name' need to be hashable: | ||
for name in values: | ||
if not is_hashable(name): | ||
raise TypeError('{}.name must be a hashable type' | ||
.format(self.__class__.__name__)) | ||
self.name = values[0] | ||
|
||
names = property(fset=_set_names, fget=_get_names) | ||
|
@@ -1365,9 +1340,9 @@ def set_names(self, names, level=None, inplace=False): | |
Examples | ||
-------- | ||
>>> Index([1, 2, 3, 4]).set_names('foo') | ||
Int64Index([1, 2, 3, 4], dtype='int64', name='foo') | ||
Int64Index([1, 2, 3, 4], dtype='int64') | ||
>>> Index([1, 2, 3, 4]).set_names(['foo']) | ||
Int64Index([1, 2, 3, 4], dtype='int64', name='foo') | ||
Int64Index([1, 2, 3, 4], dtype='int64') | ||
>>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'), | ||
(2, u'one'), (2, u'two')], | ||
names=['foo', 'bar']) | ||
|
@@ -1380,7 +1355,6 @@ def set_names(self, names, level=None, inplace=False): | |
labels=[[0, 0, 1, 1], [0, 1, 0, 1]], | ||
names=[u'baz', u'bar']) | ||
""" | ||
|
||
if level is not None and self.nlevels == 1: | ||
raise ValueError('Level must be None for non-MultiIndex') | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double-backticks on Series