Skip to content
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

ValueError: cannot convert NA to integer on some CS2 demos #305

Open
billfreeman44 opened this issue Jan 28, 2024 · 1 comment
Open

ValueError: cannot convert NA to integer on some CS2 demos #305

billfreeman44 opened this issue Jan 28, 2024 · 1 comment

Comments

@billfreeman44
Copy link

Describe the bug
Demo is from dathost. parsing it throws a ValueError: cannot convert NA to integer error.

Include Information to Reproduce
Just the basic example

Screenshots
error dump:

ValueError                                Traceback (most recent call last)
Cell In[1], line 3
      1 from awpy import parse_demo
----> 3 parsed = parse_demo(file="combine-challenger-mid1900-0_.dem")

File ~\OneDrive\Documents\GitHub\awpy\awpy\parser\demoparser.py:589, in parse_demo(file)
    587 damage = parser.parse_events([GameEvent.PLAYER_HURT.value], other=["game_phase"])
    588 damage_df = parse_damages(damage)
--> 589 damage_df = apply_round_num_to_df(damage_df, round_df)
    591 # Blockers (smokes, molotovs, etc.)
    592 effect = parser.parse_events(
    593     [
    594         GameEvent.INFERNO_STARTBURN.value,
   (...)
    598     ]
    599 )

File ~\OneDrive\Documents\GitHub\awpy\awpy\parser\demoparser.py:43, in apply_round_num_to_df(df, round_df)
     33 """Assigns a round num to each row in the DataFrame.
     34 
     35 Args:
   (...)
     40     pd.DataFrame: A dataframe with the round num assigned to column `round_num`.
     41 """
     42 print(round_df)
---> 43 interval_index = pd.IntervalIndex.from_arrays(
     44     round_df["round_start"], round_df["round_end_official"], closed="left"
     45 )
     46 intervals = pd.cut(df["tick"], interval_index)
     47 round_num_map = dict(zip(interval_index, round_df["round_num"], strict=True))

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\interval.py:300, in IntervalIndex.from_arrays(cls, left, right, closed, name, copy, dtype)
    269 @classmethod
    270 @Appender(
    271     _interval_shared_docs["from_arrays"]
   (...)
    297     dtype: Dtype | None = None,
    298 ) -> IntervalIndex:
    299     with rewrite_exception("IntervalArray", cls.__name__):
--> 300         array = IntervalArray.from_arrays(
    301             left, right, closed, copy=copy, dtype=dtype
    302         )
    303     return cls._simple_new(array, name=name)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\arrays\interval.py:539, in IntervalArray.from_arrays(cls, left, right, closed, copy, dtype)
    536 left = _maybe_convert_platform_interval(left)
    537 right = _maybe_convert_platform_interval(right)
--> 539 left, right, dtype = cls._ensure_simple_new_inputs(
    540     left,
    541     right,
    542     closed=closed,
    543     copy=copy,
    544     dtype=dtype,
    545 )
    546 cls._validate(left, right, dtype=dtype)
    548 return cls._simple_new(left, right, dtype=dtype)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\arrays\interval.py:311, in IntervalArray._ensure_simple_new_inputs(cls, left, right, closed, copy, dtype)
    308 left = maybe_upcast_numeric_to_64bit(left)
    310 right = ensure_index(right, copy=copy)
--> 311 right = maybe_upcast_numeric_to_64bit(right)
    313 if closed is None and isinstance(dtype, IntervalDtype):
    314     closed = dtype.closed

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\dtypes\cast.py:439, in maybe_upcast_numeric_to_64bit(arr)
    437 dtype = arr.dtype
    438 if is_signed_integer_dtype(dtype) and dtype != np.int64:
--> 439     return arr.astype(np.int64)
    440 elif is_unsigned_integer_dtype(dtype) and dtype != np.uint64:
    441     return arr.astype(np.uint64)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\base.py:1017, in Index.astype(self, dtype, copy)
   1015 if isinstance(values, ExtensionArray):
   1016     with rewrite_exception(type(values).__name__, type(self).__name__):
-> 1017         new_values = values.astype(dtype, copy=copy)
   1019 elif isinstance(dtype, ExtensionDtype):
   1020     cls = dtype.construct_array_type()

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\arrays\masked.py:498, in BaseMaskedArray.astype(self, dtype, copy)
    496 # to_numpy will also raise, but we get somewhat nicer exception messages here
    497 if is_integer_dtype(dtype) and self._hasna:
--> 498     raise ValueError("cannot convert NA to integer")
    499 if is_bool_dtype(dtype) and self._hasna:
    500     # careful: astype_nansafe converts np.nan to True
    501     raise ValueError("cannot convert float NaN to bool")

ValueError: cannot convert NA to integer

Additional context
n/a

@billfreeman44
Copy link
Author

#306 should fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant