Skip to content

Commit

Permalink
Merge pull request #450 from shaikh-ma/task/make_scrunch_compatible_w…
Browse files Browse the repository at this point in the history
…ith_Python311

Making scrunch compatible with Python 3.11
  • Loading branch information
jjdelc authored Feb 12, 2024
2 parents 13c3de1 + 6973a94 commit e75284c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
9 changes: 7 additions & 2 deletions scrunch/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
# ... unless you have to worry about pandas
pd = None


if sys.version_info.major == 3:
from collections.abc import Mapping
else:
from collections import Mapping

import six

import pycrunch
Expand Down Expand Up @@ -702,7 +708,7 @@ def __readonly__(self, *args, **kwargs):
del __readonly__


class DatasetVariablesMixin(collections.Mapping):
class DatasetVariablesMixin(Mapping):
"""
Handles dataset variable iteration in a dict-like way
"""
Expand Down Expand Up @@ -3411,4 +3417,3 @@ def execute(self, csv_file):
# Always delete the tmp dataset no matter what
tmp_ds.delete()


13 changes: 10 additions & 3 deletions scrunch/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
import scrunch
from scrunch.variables import validate_variable_url

import sys

PY311 = sys.version_info[:2] == (3, 11)

if six.PY2:
from urllib import urlencode
Expand Down Expand Up @@ -280,9 +283,13 @@ def _parse(node, parent=None):
# We will take the subvariable alias bit from the subscript
# and return an object with the array and subvariable alias
array_alias = dict(ast.iter_fields(fields[0][1]))["id"]
name_node = dict(ast.iter_fields(fields[1][1]))["value"]
subscript_fields = dict(ast.iter_fields(name_node))
subvariable_alias = subscript_fields["id"]
if PY311:
name_node = dict(ast.iter_fields(fields[1][1]))
subvariable_alias = name_node["id"]
else:
name_node = dict(ast.iter_fields(fields[1][1]))["value"]
subscript_fields = dict(ast.iter_fields(name_node))
subvariable_alias = subscript_fields["id"]
return {"variable": {"array": array_alias, "subvariable": subvariable_alias}}
# "Non-terminal" nodes.
else:
Expand Down
8 changes: 7 additions & 1 deletion scrunch/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import re

import six
import sys

if sys.version_info.major == 3:
from collections.abc import Iterable
else:
from collections import Iterable

import pycrunch
import scrunch.datasets
Expand Down Expand Up @@ -181,7 +187,7 @@ def is_root(self):
def _validate_alias_arg(alias):
if isinstance(alias, six.string_types):
alias = [alias]
if not isinstance(alias, collections.Iterable):
if not isinstance(alias, Iterable):
raise ValueError(
'Invalid list of aliases/ids/groups to be inserted'
' into the Group.'
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py36,py37,py38,py39,{py27,py36,py37,py38,py39}-pandas
envlist = py27,py36,py37,py38,py39,py311{py27,py36,py37,py38,py39,py311}-pandas
minversion = 2.4
skip_missing_interpreters = true

Expand All @@ -10,6 +10,7 @@ python =
3.7: py37,py37-pandas
3.8: py38,py38-pandas
3.9: py39,py39-pandas
3.11: py311,py311-pandas

[testenv]
deps =
Expand Down

0 comments on commit e75284c

Please sign in to comment.