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

Fix pandas 2.0 compatibility #176

Closed
JohanKJSchreurs opened this issue Apr 11, 2023 · 0 comments · Fixed by #177
Closed

Fix pandas 2.0 compatibility #176

JohanKJSchreurs opened this issue Apr 11, 2023 · 0 comments · Fixed by #177
Assignees

Comments

@JohanKJSchreurs
Copy link
Contributor

JohanKJSchreurs commented Apr 11, 2023

There are some new errors with Pandas 2.0, while we don't have those errors with Pandas 1.5.

The pandas dependency is currently not pinned to a version.
We could start to pin it, but at present that would need to be pinned to version 1.5.x to make the tests pass. That means we will still have a problem later on when we upgrade to Pandas 2.0.

So it would be best to fix the issues and make the Python driver compatible with Pandas 2.0.x.

Example error logs from pytest

Error 1:

Can be traced back to a breaking change in the Pandas API:

See also: https://pandas.pydata.org/docs/whatsnew/v2.0.0.html#backwards-incompatible-api-changes

Removed the closed argument in date_range() and bdate_range() in favor of inclusive argument (GH40245)

=================================== FAILURES ===================================
___________________________ test_period_to_intervals ___________________________

...
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

start = Timestamp('2021-06-01 00:00:00'), end = Timestamp('2021-06-24 00:00:00')
periods = None, freq = 'W', tz = None, normalize = False, name = None
inclusive = 'both', unit = None, kwargs = {'closed': 'left'}

    def date_range(
        start=None,
        end=None,
        periods=None,
        freq=None,
        tz=None,
        normalize: bool = False,
        name: Hashable = None,
        inclusive: IntervalClosedType = "both",
        *,
        unit: str | None = None,
        **kwargs,
    ) -> DatetimeIndex:
        """
        Return a fixed frequency DatetimeIndex.
     
      # Removed part of this docstring for brevity
    
        >>> pd.date_range(start="2017-01-01", periods=10, freq="100AS", unit="s")
        DatetimeIndex(['2017-01-01', '2117-01-01', '2217-01-01', '2317-01-01',
                       '2417-01-01', '2517-01-01', '2617-01-01', '2717-01-01',
                       '2817-01-01', '2917-01-01'],
                      dtype='datetime64[s]', freq='100AS-JAN')
        """
        if freq is None and com.any_none(periods, start, end):
            freq = "D"
    
>       dtarr = DatetimeArray._generate_range(
            start=start,
            end=end,
            periods=periods,
            freq=freq,
            tz=tz,
            normalize=normalize,
            inclusive=inclusive,
            unit=unit,
            **kwargs,
        )
E       TypeError: _generate_range() got an unexpected keyword argument 'closed'

venv38/lib64/python3.8/site-packages/pandas/core/indexes/datetimes.py:945: TypeError

Error 2:

_____________________ test_aggregate_polygon_result_basic ______________________

self = DatetimeIndex(['2019-10-15 08:15:45', '2019-11-11 01:11:11'], dtype='datetime64[ns]', name='t', freq=None)
key = Timestamp('2019-10-15 08:15:45+0000', tz='UTC')

    def _disallow_mismatched_indexing(self, key) -> None:
        """
        Check for mismatched-tzawareness indexing and re-raise as KeyError.
        """
        # we get here with isinstance(key, self._data._recognized_scalars)
        try:
            # GH#36148
>           self._data._assert_tzawareness_compat(key)

venv38/lib64/python3.8/site-packages/pandas/core/indexes/datetimes.py:532: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <DatetimeArray>
['2019-10-15 08:15:45', '2019-11-11 01:11:11']
Length: 2, dtype: datetime64[ns]
other = Timestamp('2019-10-15 08:15:45+0000', tz='UTC')

    def _assert_tzawareness_compat(self, other) -> None:
        # adapted from _Timestamp._assert_tzawareness_compat
        other_tz = getattr(other, "tzinfo", None)
        other_dtype = getattr(other, "dtype", None)
    
        if is_datetime64tz_dtype(other_dtype):
            # Get tzinfo from Series dtype
            other_tz = other.dtype.tz
        if other is NaT:
            # pd.NaT quacks both aware and naive
            pass
        elif self.tz is None:
            if other_tz is not None:
>               raise TypeError(
                    "Cannot compare tz-naive and tz-aware datetime-like objects."
E                   TypeError: Cannot compare tz-naive and tz-aware datetime-like objects.

venv38/lib64/python3.8/site-packages/pandas/core/arrays/datetimes.py:744: TypeError

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

Successfully merging a pull request may close this issue.

1 participant