-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Indexing into a series with multi-index containing periods raises an exception #22803
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
Labels
Milestone
Comments
@PatrickDRusk : That does look a little odd indeed! |
toobaz
added a commit
to toobaz/pandas
that referenced
this issue
Nov 7, 2018
toobaz
added a commit
to toobaz/pandas
that referenced
this issue
Nov 7, 2018
Unrelated to In [2]: hasattr(s, '__next__')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
129 try:
--> 130 return self.mapping.get_item(val)
131 except (TypeError, ValueError):
/home/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
921
--> 922 cpdef get_item(self, int64_t val):
923 cdef khiter_t k
TypeError: an integer is required
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
/home/nobackup/repo/pandas/pandas/core/indexes/period.py in get_loc(self, key, method, tolerance)
703 try:
--> 704 return self._engine.get_loc(key)
705 except KeyError:
/home/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
107
--> 108 cpdef get_loc(self, object val):
109 if is_definitely_invalid_key(val):
/home/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
131 except (TypeError, ValueError):
--> 132 raise KeyError(val)
133
KeyError: '__next__'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
/home/nobackup/repo/pandas/pandas/_libs/tslibs/parsing.pyx in pandas._libs.tslibs.parsing.parse_datetime_string_with_reso()
163 try:
--> 164 parsed, reso = dateutil_parse(date_string, _DEFAULT_DATETIME,
165 dayfirst=dayfirst, yearfirst=yearfirst,
/home/nobackup/repo/pandas/pandas/_libs/tslibs/parsing.pyx in pandas._libs.tslibs.parsing.dateutil_parse()
316 msg = "Unknown datetime string format, unable to parse: {timestr}"
--> 317 raise ValueError(msg.format(timestr=timestr))
318
ValueError: Unknown datetime string format, unable to parse: __next__
During handling of the above exception, another exception occurred:
DateParseError Traceback (most recent call last)
<ipython-input-2-c6c5c35d0556> in <module>()
----> 1 hasattr(s, '__next__')
/home/nobackup/repo/pandas/pandas/core/generic.py in __getattr__(self, name)
4726 return object.__getattribute__(self, name)
4727 else:
-> 4728 if self._info_axis._can_hold_identifiers_and_holds_name(name):
4729 return self[name]
4730 return object.__getattribute__(self, name)
/home/nobackup/repo/pandas/pandas/core/indexes/base.py in _can_hold_identifiers_and_holds_name(self, name)
2098 """
2099 if self.is_object() or self.is_categorical():
-> 2100 return name in self
2101 return False
2102
/home/nobackup/repo/pandas/pandas/core/indexes/multi.py in __contains__(self, key)
572 hash(key)
573 try:
--> 574 self.get_loc(key)
575 return True
576 except (LookupError, TypeError):
/home/nobackup/repo/pandas/pandas/core/indexes/multi.py in get_loc(self, key, method)
2232
2233 if not isinstance(key, tuple):
-> 2234 loc = self._get_level_indexer(key, level=0)
2235 return _maybe_to_slice(loc)
2236
/home/nobackup/repo/pandas/pandas/core/indexes/multi.py in _get_level_indexer(self, key, level, indexer)
2486 else:
2487
-> 2488 code = level_index.get_loc(key)
2489
2490 if level > 0 or self.lexsort_depth == 0:
/home/nobackup/repo/pandas/pandas/core/indexes/period.py in get_loc(self, key, method, tolerance)
708
709 try:
--> 710 asdt, parsed, reso = parse_time_string(key, self.freq)
711 key = asdt
712 except TypeError:
/home/nobackup/repo/pandas/pandas/_libs/tslibs/parsing.pyx in pandas._libs.tslibs.parsing.parse_time_string()
126 yearfirst = get_option("display.date_yearfirst")
127
--> 128 res = parse_datetime_string_with_reso(arg, freq=freq,
129 dayfirst=dayfirst,
130 yearfirst=yearfirst)
/home/nobackup/repo/pandas/pandas/_libs/tslibs/parsing.pyx in pandas._libs.tslibs.parsing.parse_datetime_string_with_reso()
167 except Exception as e:
168 # TODO: allow raise of errors within instead
--> 169 raise DateParseError(e)
170 if parsed is None:
171 raise DateParseError("Could not parse {dstr}".format(dstr=date_string))
DateParseError: Unknown datetime string format, unable to parse: __next__ Preparing a PR. |
4 tasks
toobaz
added a commit
to toobaz/pandas
that referenced
this issue
Nov 7, 2018
TomAugspurger
pushed a commit
that referenced
this issue
Nov 7, 2018
JustinZhengBC
pushed a commit
to JustinZhengBC/pandas
that referenced
this issue
Nov 14, 2018
tm9k1
pushed a commit
to tm9k1/pandas
that referenced
this issue
Nov 19, 2018
Pingviinituutti
pushed a commit
to Pingviinituutti/pandas
that referenced
this issue
Feb 28, 2019
Pingviinituutti
pushed a commit
to Pingviinituutti/pandas
that referenced
this issue
Feb 28, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code Sample, a copy-pastable example if possible
Problem description
Running the code above causes an exception with a long traceback:
This appears to happen only if the series has a multi-index that contains periods as one of its levels. Datetimes won't cause it, for instance.
The
s[~s.isnull()]
is equivalent tos.dropna()
, which does work.Neither
~s.isnull()
nors[[True]]
cause the exception by themselves. It appears to take the combination.Expected Output
Output of
pd.show_versions()
pandas: 0.23.4
pytest: 3.8.0
pip: 18.0
setuptools: 40.2.0
Cython: 0.28.5
numpy: 1.14.5
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: None
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 2.2.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: 1.2.11
pymysql: 0.9.2
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: